renderConfluenceMacro - xhtml-macro - Confluence 4.*

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">

&lt;parameters&gt;
       		&lt;parameter name="limit" type="string" /&gt;
     	&lt;/parameters&gt;
&lt;/xhtml-macro&gt;

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

This widget could not be displayed.

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]

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
Community showcase
Posted Monday in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

436 views 4 6
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you