This server will be upgraded at 3pm Sydney time on December 3rd (December 2nd, 8pm PST) and will be down for up to 30 minutes.

Render any text from a user macro

Unknown macro: {alias}

Declare the following two velocity macros:

  • you can declare the velocity macros below in the body of any user macro that needs to use them
  • we declare it once, alone, in a confluence user macro called 'Render'. we call this confluence user macro from the dashboard. Once it executes once, confluence keeps the velocity macro '#render()' in memory until it is redeclared. ( after asking confluence support, this seems to be undocumented and may or may not be true in future versions of Confluence or Velocity)
  • if you declare the velocity user macros below in the appropriate .vm, you don't need to declare it in any user macro and only need to declare it once
    #macro(trimp $xhtml)
    ## remove leading <p> and trailing </p>
    #if($xhtml.startsWith("<p>",0) && $xhtml.endsWith("</p>"))
    #set($len=$xhtml.length()-$generalUtil.convertToInteger(4))
    #set($xhtml=$xhtml.substring(3,$len))
    #end
    $xhtml
    #end
    #macro(render $wiki)
    #set($globalHelper=$action.getGlobalHelper())
    #if($content)## i. e. we render a normal page
    #set($renderer=$globalHelper.getWikiStyleRenderer())
    #set($context=$content.toPageContext())
    #set($xhtml=$renderer.convertWikiToXHtml($context, $wiki).replaceAll("\n|\r",""))
    #else## we are e. g. in Global Template Preview
    #set($xhtml=$globalHelper.renderConfluenceMacro($wiki).replaceAll("\n|\r",""))
    #end
    #trimp(${xhtml})
    #end
    #render($body)
    

Now you can use this syntax to render content:

#render($body)

#render("[test|CONFEXT:edit-include user macro]")

#set($wiki="{attachments}")
#set($html="#render($wiki)")

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.