renderConfluenceMacro - xhtml-macro - Confluence 4.*

Felix Grund (Scandio)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 6, 2012

Hi,

I already had a look at these questions, without a clear answer for my issue:

https://answers.atlassian.com/questions/54365/confluence-4-x-why-can-built-in-macros-still-be-inserted-using-wiki-markup-but-apparently-not-my-custom-macro

https://answers.atlassian.com/questions/24391/replacement-for-renderconfluencemacro

I am developing a Confluence plugin for the latest version 4.3-RC1 (the question should apply to all 4.* Confluence versions). Rendering the Macro inside the Wysiwyg-Editor works fine. However, I can't find a way to embedd the macro inside of my .vm template. In previous Confluence versions, this was achieved by the #renderConfluenceMacro function. I can't get this function working with my xhtml-macro, I only get the error "unknown macro".

However, rendering a built-in Confluence macro like "loremipsum" with #renderConfluenceMacro("{loremipsum}") works fine.

So, how can I render a macro within a .vm template in Confluence 4.*? In atlassian-plugin.xml, my macro is defined as follows:

<xhtml-macro name="scevents" class="de.scandio.confluence.plugins.sc.events.macros.Event.TeaserListMacro" key="scevents">

<parameters>
       		<parameter name="limit" type="string" />
     	</parameters>
</xhtml-macro>

I also tried the approach using the XhtmlContent Interface as specified in one of the above questions:

$xhtmlContent.convertWikiToView("{scevents}", null, null)

The $xhtmlContent is a DefaultXhtmlContent instance. This call just gives me a NullPointerException using the two null-parameters.

I appreciate any help, since this is a fairly important plugin for us.

Regards,
Felix Grund [Scandio GmbH]

 

 

 

1 answer

1 accepted

2 votes
Answer accepted
Deleted user October 14, 2012

Hi Felix,

XHTML Macro s can not be rendered with $action.getHelper().renderConfluenceMacro("...").

To render your macro, you must inject the XhtmlContent-Interface in your action.

After that, you can render the macro with following call:

$xhtmlContent.convertStorageToView("<ac:macro ac:name=\"Example Macro\" />", null)

When you use that in velocity template the return is a escaped string.

In my case i add a new function to my action called getMacroAsHtml() and put an @HtmlSafe above.

So i get an unescaped html string.

I hope that this comment proves helpful.

Regards,
Markus Weigelt [Communardo Software GmbH]

Felix Grund (Scandio)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 14, 2012

Hi Markus,

thank you very much for your reply. When I was searching for a solution to my problem, I ended up migrating my macro according to this guide. At first sight, however, your solution seems to be more elegant. I'm going to look at it again when the issue occurs next time.

Regards,
Felix [Scandio GmbH]

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events