Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Rendering a XHTML macro in the standard Page Layout (page.vmd)

Eddie Stanley July 1, 2013

I've written a confluence macro contained in a plugin (v2). The macro is a XHTML style one (we're using Confluence 5.x and this seems to be the way forward). The macro works fine when editing in the WYSIWYG editor but I'd like to include it in ALL of our confluence pages.

I thought I could achieve this by customizing the "Page Layout" decorator. This is what I tried initially:

<div id="main-content" class="wiki-content">
           $body
           $helper.renderConfluenceMacro("{mymacro}")
        </div>

When it came to rendering the page, it told me that it couldn't find the maro. Based on trawling the net people were telling me that I had to define both <macro> and <xhtml> forms of the macro in atlassian-plugin.xml - this seems like a drag, but I couldn't make it worth either - I get a class cast exception expecting com.atlassian.renderer.v2.macro.Macro (my plugin implements com.atlassian.confluence.macro.Macro).

I then tried the following:

&lt;div id="main-content" class="wiki-content"&gt;
           $body
           $xhtmlContent.convertStorageToView("&lt;ac:macro ac:name=\"mymacro\" /&gt;", $context)
        &lt;/div&gt;

This didn't work either (I just got the text "$xhtmlContent.convert..." in the output HTML).

I'm really at a loss here - this seems like a pretty common and reasonable use case? Surely I'm missing something.

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
July 1, 2013

OK, this is a bit of a dirty hack, but...

Try wrapping it in a user macro and adding that in the following way:

$helper.renderConfluenceMacro("{xhtml-wrapper-user-macro}")

Your user macro would probably look similar to this:

## Macro title: XHTML macro wrapper
## Macro has a body: N
## Body processing: n/a
## Output: HTML

## @noparams

&lt;ac:macro ac:name="mymacro" /&gt;

The user macro should be able to be rendered by the decorator in the old way preventing you from having to make your new macro backwards compatible.

Eddie Stanley July 1, 2013

I think I tried that (and it didn't work) but will give it another go.

Eddie Stanley July 2, 2013

Thanks - this does in fact work, howerver I don't get the same conversion context (this macro interacts with another macro I've written via shared state set in the conversion context).

Eddie Stanley July 7, 2013

I'm after an answer that includes the conversion context (for it to be of any use in my application).

TAGS
AUG Leaders

Atlassian Community Events