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:
<div id="main-content" class="wiki-content"> $body $xhtmlContent.convertStorageToView("<ac:macro ac:name=\"mymacro\" />", $context) </div>
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.
Community moderators have prevented the ability to post new answers.
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 <ac:macro ac:name="mymacro" />
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.
I think I tried that (and it didn't work) but will give it another go.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm after an answer that includes the conversion context (for it to be of any use in my application).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.