This documentation relates to the latest version of Confluence.
If you are using an earlier version, please go to the documentation home page and select the relevant version.

User Macros

All Versions

Confluence 3.0 Documentation

User macros allow you to create simple formatting macros using the Confluence web interface.

User Macro Plugins and Macro Plugins

If you want to distribute your user macro as a plugin, please see User Macro Plugins. If you want to create more complex, programmatic macros in Confluence, you may need to write a Macro Plugin. Note also that Macro Plugins and User Macro Plugins can appear in the Confluence Notation Guide, whereas User Macros do not. Here is an example of the Confluence Notation Guide.

You need to have System Administrator permissions in order to create user macros.

On this page:

Creating a User Macro

To create a user macro,

  1. Go to the 'Administration Console' and click 'User Macros' in the left-hand panel.
  2. Click 'Create a User Macro' at the top of the list of macros.
  3. Supply the information in the input fields as explained below, then click the 'Save' button.


Screenshot: Creating a User Macro



Input fields:

  • 'Macro Name' — Enter the text that you will type, within curly brackets, to invoke the macro from within a page. For example, to invoke the 'floatright' macro defined in the above screenshot, you would type:
    {floatright}
    
  • 'Macro has a body' — Check this box if you will pass body-text to the macro when you invoke it from within a page, e.g. :
    {floatright}my text{floatright}
    

    If you select 'Macro has a body', anything the user types within the body of the macro will be available in the macro in the $body variable. The options below allow you to tell Confluence to pre-process the body before it is placed in the macro output:

    • Use unprocessed macro body — The body of the macro will be output exactly as entered, including any HTML markup. For example if the macro body is <b>body</b>, it will be displayed as body in the page.
    • Escape HTML in macro body — The body of the macro will be output with HTML markup escaped. So if the macro body is <b>body</b>, it will be displayed as <b>body</b> in the page.
    • Convert macro body wiki markup to HTML — The body of the macro will be converted from wiki text to HTML markup. So if the macro body is *body*, it will be displayed as body in the page.
  • 'Output' — Choose one of the following options:
    • 'Macro generates HTML markup' — Choose this if you wish to write your Template in HTML markup (as shown in the above screenshot).
    • 'Macro generates wiki markup' — Choose this if you wish to write your Template in wiki markup.
  • 'Template' — This specifies what the macro will do. Write this using the Velocity templating language. Here is more information on the Velocity project.
    Note: If you ticked Macro has a body, your template can refer to the body-text by specifying $body.

Examples

Example 1: User Macro to Create a Red Box

As an example, let's write a simple macro that simply creates a red box (using an existing Confluence style) around some text (useful for writing about error conditions for example - hence the macro name 'error').

After clicking "New User Macro", enter error as the Name of your macro, and then put the following in the Template text area:

<div class="errorbox">$body</div>



Then click Add. You should now see your new macro in the User Macros library, and you can now enable and disable it individually.
To use the macro within a page, you would add notation like:

{error}This is bad{error}



And your page would (magically!) have an error box on it, like so:

This is bad

Example 2: User Macro to Display 'Hello World'

Take a look at an example of a 'Hello World' macro.

Example 3: User Macro to Demonstrate the Use of Parameters

This example demonstrates how you can pass parameters into your macro. Let's say you want to write your own font colour macro:

<span style="color: $param0">$body</span>



The usage of this macro would be:

{colour:red}Some example text{colour}



which will produce:
Some example text

If your macro requires more than one parameter, you can use variables $param0 to $param9 to represent them. To specify multiple parameters, use:

{colour:red|blue|green}



Where red, blue and green are the 1st, 2nd and 3rd parameters respectively.

Alternatively, you can also use explicitly named parameters in your macro. These macro parameters will appear as variables with the name $param<x> where <x> is the name of your parameter. To specify named parameters, use:

{style:colour=red}

In your user macro you can then use $paramcolour which will have the value red in this case.

Available Objects

The user macro above uses the $body object, which is available for use within your user macro template if the macro has a body.

You can pass parameters to your user macro in the same way as any other macro, separated by the pipe | sign. These parameters are provided to your template as param1, param2, ... paramN.

The complete list of objects available for use are:

Name Description Doc Reference
$body The body of the macro (if the macro has a body)  
$param0-n The parameters passed to your macro (as available)  
$param<name> Named parameters passed to your macro (as available)  
$config The BootstrapManager object, useful for retrieving Confluence properties BootstrapManager
$content The current ContentEntity object that this macro is a included in (if available) ContentEntityObject
$space The Space object that this content object is located in (if relevant) Space
$generalUtil A GeneralUtil object, with useful utility methods for URL encoding etc GeneralUtil
$action A blank ConfluenceActionSupport object, useful for retrieving i18n text if needed ConfluenceActionSupport
$webwork A VelocityWebWorkUtil object, for its htmlEncode() method VelocityWebWorkUtil
$req The current HttpServletRequest object (if the page is rendered as a result of an HTTP request) HttpServletRequest
$res The corresponding HttpServletResponse object (not recommended to be played with) HttpServletResponse
$userAccessor For retrieving users, groups and checking membership UserAccessor
Velocity Context in Exporters

The above context is not inherited by the Velocity context created for PDF or Word exports. To see the available objects in that context, see this page.

Normally, a parameter like $param2 that is missing will appear as '$param2' in the output. To display nothing when a variable is not set, use an exclamation mark after the dollar sign like '$!param2'.

You can read more about object usage in the Velocity Template Overview.

User Macro Library

Below is a list of existing user macros, written by other Confluence users. If you wish, you can install these on your Confluence site.

Be careful when installing user macros from unknown authors
RELATED TOPICS

User Macro Plugins
Macro Plugins
Confluence Plugin Guide

Labels

admin-macros admin-macros Delete
user user Delete
macro macro Delete
usermacro usermacro Delete
template-related template-related Delete
hello hello Delete
world world Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Jul 08, 2004

    Anonymous says:

    I want to write a macro that uses other Confluence macros (like {color}) but whe...

    I want to write a macro that uses other Confluence macros (like {color}) but when I type Confluences syntax inside the macro template it appears as is. Is there a way to gain access to this stuff from inside the Velocity template? Or do I have to write plain HTML? Any pointers are appreciated.

    1. Aug 27, 2004

      David Mankin says:

      I can't even make HTML work. It seems to be escaped, and therefore the tags appe...

      I can't even make HTML work. It seems to be escaped, and therefore the tags appear in the page. Does anybody know what it takes to get either Confluence markup or html markup to appear when I use $body in the macro?

      1. Aug 29, 2005

        Daniel Ostermeier says:

        Confluence has an Unknown macro: {html} macro that allows you to enter HTML d...

        Confluence has an

        Unknown macro: {html}

        macro that allows you to enter HTML directly into the wiki page.

        By default, this macro is disabled for security reasons. To enable this macro, go to "Administration | General Configuration | Plugins | HTML Macros" and click enable plugin.

    2. Aug 26, 2005

      Anonymous says:

      yes, i have the same problem. Is there a velocity- available function that force...

      yes, i have the same problem. Is there a velocity- available function that forces the rendering of some wiki-formatted text?

      1. Aug 29, 2005

        Mingyi Liu says:

        Yeah, same wish here. I'll check if I could add it to wish list (or it's alread...

        Yeah, same wish here. I'll check if I could add it to wish list (or it's already there).

        Would it be difficult to implement it? Seems to me that Confluence just needs to pass in an object with a method that runs wiki syntax engine.

        1. Aug 30, 2005

          Daniel Ostermeier says:

          A feature request has been raised for this and can be tracked via http://jira.at...

          A feature request has been raised for this and can be tracked via http://jira.atlassian.com/browse/CONF-3887

          If you would like to see this feature included in confluence, please vote for it.

    3. Aug 28, 2005

      David Loeng says:

      This is not possible as all text entered in the body of a user macro is left alo...

      This is not possible as all text entered in the body of a user macro is left alone by the renderer.

      Cheers,
      Dave

    4. Sep 29, 2005

      Mark Michaelis says:

      It's a bit tricky but the following works: #set($globalHelper=$action.getGlo...

      It's a bit tricky but the following works:

      #set($globalHelper=$action.getGlobalHelper())
      #set($renderer=$globalHelper.getWikiStyleRenderer())
      #set($context=$content.toPageContext())
      #set($renderedContent=$renderer.convertWikiToXHtml($context, $body))
      ${renderedContent}
      
      1. Sep 30, 2005

        Mark Michaelis says:

        Well, this is even more powerful than any $renderedBody-variable which might be ...

        Well, this is even more powerful than any $renderedBody-variable which might be used. Just see here:

        ...
        #set($context=$content.toPageContext())
        #set($renderedContent=$renderer.convertWikiToXHtml($context, "{panel:title=My Title}${body}{panel}))
        ${renderedContent}
        

        The only problem I have now is that I also want to create Panels containing Wikified-Lists this way. E. g.:

        #set($content="{panel}")
        #foreach($line in $array)
        #set($content="${content}* ${line}<newline>")
        #end
        

        The <newline> is my problem: How to get a newline-character inside there so that Confluence finally renders a content like this:

        {panel}
        * line 1
        * line 2
        {panel}
        

        ?? '\n' does not work. It will render a content like:

        {panel}* line 1\n* line 2\n{panel}
        

        Any ideas welcome!

        1. Dec 13, 2005

          Stefan Baader says:

          Good hint Mark one little bug: you forgot the second " in the line before last:...

          Good hint Mark

          one little bug: you forgot the second " in the line before last:

          \#set($globalHelper=$action.getGlobalHelper())
          \#set($renderer=$globalHelper.getWikiStyleRenderer())
          \#set($context=$content.toPageContext())
          \#set($renderedContent=$renderer.convertWikiToXHtml($context, "{panel:title=My Title}${body}{panel}"))
          ${renderedContent}
          
        2. Jun 03, 2006

          James Mortimer says:

          Did anyone report a workaround for newline in velocity script 'User Macro's? I'...

          Did anyone report a workaround for newline in velocity script 'User Macro's?

          I'm using the following patchy workaround, but there must be a better way.

          #macro(newline)
          
          #end
          #set($newline="#newline()")
          

          Now, $newline or #newline() will return a newline character. $newline is faster as the velocity renderer doesn't have to start up and re-render the 'newline' content each time. It actually makes a difference if you are using it in a large loop.

          So mark's code would look like:

          #set($content="{panel}$newline")   
          #foreach($line in $array)   
          #set($content="${content}* ${line}$newline")   
          #end
          #set($content="$content$newline{panel}")  
          

          which renders

          {panel}
          * line 1
          * line 2
          {panel}
          

          and you might want to use it like this, to replace all \n with newline characters:

          #set($wiki=$wiki.replaceALL('\\n',$newline))
          
          1. Jun 03, 2006

            James Mortimer says:

            Depending on your opinion, this code for getting a newline character is a bit cl...

            Depending on your opinion, this code for getting a newline character is a bit cleaner but still patchy.

            #set($newline="")#set($newline=$newline.format('%n',null))
            
            1. you need to have a string defined to get at the .format property, #hence set($newline="")
            2. %n is a platform independant newline characters
            3. null is because format requires an object for any replacement codes. We're not using any.
      2. Sep 30, 2005

        Mark Michaelis says:

        Oops. One step to far. You can even make it much more easy and without errors wh...

        Oops. One step to far. You can even make it much more easy and without errors when rendering such errors in the global-templates-preview:

        #set($globalHelper=$action.getGlobalHelper())
        #set($renderedContent=$globalHelper.renderConfluenceMacro($body))
        ${renderedContent}
        
        1. Sep 30, 2005

          Mark Michaelis says:

          Hm. Seems as if this only works for simple bodies. I. e. you either have to use ...

          Hm. Seems as if this only works for simple bodies. I. e. you either have to use the first workaround and ignore the errors in the Global Templates Preview or you get even more complex. The following is an example-macro which just renders the body (but of course you might extend $wiki as you like):

          #set($wiki=$body)
          #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))
          #else ## we are e. g. in Global Template Preview
          #set($xhtml=$globalHelper.renderConfluenceMacro($wiki))
          #end
          ${xhtml}
          
          1. Oct 05, 2005

            Mark Michaelis says:

            For the different behavior of renderConfluenceMacro and convertWikiToXHtml I rai...

            For the different behavior of renderConfluenceMacro and convertWikiToXHtml I raised an issue CONF-4220 which hopefully will be fixed soon.

            The different behavior will show up as soon as e. g. $body contains macros which need access to the current space. E. g. {blog-posts} will fail with just using renderConfluenceMacro (it won't show the news of the current space).

  2. Aug 13, 2004

    Tim Colson says:

    Sure would be nice to have named parameters. Unknown macro: {mymacro} To prev...

    Sure would be nice to have named parameters.

    Unknown macro: {mymacro}

    To prevent namespace collision, just stuff the macro params into a Hash with the same velocity object name as the macro itself, for example:

    $mymacro.title $mymacro.name

    1. Jun 09, 2006

      Mark Michaelis says:

      I am astonished. With Confluence 2.2 named parameters seem to work. Just tried b...

      I am astonished. With Confluence 2.2 named parameters seem to work. Just tried by try-and-error and got e. g. $paramstyle to refer to the value of argument "style=something".

      It would be nice to know if this is a "first try" or if this is finalized so that we can base new user macros on this new feature. And if so, it should be documented here

      1. Sep 14, 2006

        James Mortimer says:

        any indication yet if this is a hidden alpha-feature or something that will pers...

        any indication yet if this is a hidden alpha-feature or something that will persist?

  3. Aug 13, 2004

    Tim Colson says:

    Doh... I put in an example but Confluence is trying to eval it inline – he...

    Doh... I put in an example but Confluence is trying to eval it inline – hence the unknown macro above.

    {mymacro:title=Bright Idea Dude|name=Timo}

  4. Dec 14, 2004

    Kevin James says:

    So it appears the $param1-n are passed in as strings. How can I pass in a value...

    So it appears the $param1-n are passed in as strings. How can I pass in a value to determine how many times I loop? I want a macro that says

    Unknown macro: {tab}

    where $param1 indicates how many times to loop.

    So my template looks like this:
    #foreach( $foo in [1 .. $param1] )
    $nbsp;
    #end

    However, this does NOT work. Any ideas how I might make this work? The velocity documentation says I should be able to specify a range like [$foo .. $bar], but the only way I've been able to make this work is where I #set($foo=1) and #set($bar=3). How can I let my $param1 define how many times I loop?

    1. May 18, 2005

      Charles Miller says:

      This is not currently supported, because $param1 contains a string, and thus can...

      This is not currently supported, because $param1 contains a string, and thus can't be used as a loop counter.

      If you would like to see this capability in user macros, please file an enhancement request at http://jira.atlassian.com

      1. Aug 29, 2005

        Mingyi Liu says:

        Well, it's actually easily doable in Confluence: #foreach ($i in [1..$generalU...

        Well, it's actually easily doable in Confluence:

        #foreach ($i in [1..$generalUtil.convertToInteger($param0)])
          <b>loop #$i</b><br>
        #end
        

        The above code runs correctly in 1.4.3 (didn't test it in earlier versions but no reason why it should not work).

        I truly wish that Confluence could provide better docs for the objects listed though, 'cause obviously it's too skimpy to be of much help to people.

  5. Jul 08, 2005

    marvin greenberg says:

    It would be very HELPFUL if on the page above you added links to what on earth a...
  6. Oct 13, 2005

    Mark Michaelis says:

    I think it would be a good idea to have a "User Macro Library" just as it has be...

    I think it would be a good idea to have a "User Macro Library" just as it has been introduced for the "Scaffolding Macros". They might serve as examples and of course might be of general interest. I think this is better than the alternative to make every User Macro a Confluence Extensions appearing in the Extension Space. Perhaps we could in addition point from the Extension Space to the User Macro-Library instead.

  7. Oct 13, 2005

    Mark Michaelis says:

    Is there any chance to make the User Macros visible in the Notation Guide? Other...

    Is there any chance to make the User Macros visible in the Notation Guide? Otherwise they will have to be documented in some of the spaces to make them known to the Confluence-Users.

    I suggest something like JavaDoc, e. g.

    #/**
    #* Does *something* useful.
    #* @notation \{something-useful\}_Content_\{something-useful\}
    #* @notation \{something-useful:_Some Title_\}_Content_\{something-useful\}
    #* @param 0 some useful title
    #* @param 1 some useful option
    #* @param body some useful content
    #*/
    

    Where the description will appear as rendered Wiki-Content in the Comment-column while the notations are listed (separated by newlines) in the Notation-column.

    1. Oct 13, 2005

      Jonathan Nolen says:

      This feature request is being tracked at CONF-2294. Please go vote for it.

      This feature request is being tracked at CONF-2294. Please go vote for it.

  8. Nov 07, 2005

    Jody Garnett says:

    Thanks for the help commenters - here is the hardest little thing I have had to ...

    Thanks for the help commenters - here is the hardest little thing I have had to write:

    #set($globalHelper=$action.getGlobalHelper())
    #set( $news=$space.blogPosts )
    #set( $count=0)
    
    #foreach($post in $news)  
      #set($count=$count+1)
    #end
    
    #set($number= $generalUtil.convertToInteger($param0))
    
    #set($start=1)
    #if( $number > 0)
      #set($start= $count - $number)
    #end
    
    #foreach( $index in [$count .. $start] )
      #set($index2= $index - 1 )
      #foreach($post in $news.subList( $index2, $index) )  
        <a href="/confluence/display/pages/viewpage.action?pageId=${post.id}">$post.realTitle</a><br/>
      #end
    #end
    

    This provides links the the indicated number of recent log posts. The hard part here was reversing the list. Could not get size, Collections.reverse or even get to function ...

  9. Jan 12, 2006

    Othman Alaoui says:

    It looks like parameters are now 0-based rather than 1-based. Incrementing i in ...

    It looks like parameters are now 0-based rather than 1-based. Incrementing i in $parami in all my user macros fixed the problem I had after upgrading from 1.3.5 to 2.1.1.

    1. Jan 12, 2006

      Othman Alaoui says:

      Btw the following should be fixed in the page (replace bold by param0): You can...

      Btw the following should be fixed in the page (replace bold by param0):

      You can pass parameters to your user macro in the same way as any other macro (separated by | signs), these parameters are provided to your template as param1, param2. . . paramN.

      1. Jan 12, 2006

        Othman Alaoui says:

        hmm this is odd: with only one parameter, it only works if I use 0 as the start ...

        hmm this is odd: with only one parameter, it only works if I use 0 as the start index, but with multiple parameters i can keep using 1 as the start index:

        <a xhref="notes://$body">$param0</a>
        

         

        <A xhref=https://myapp/AZ?p=#if($param1 == "doc")1#elseif($param1 == "com")2#end&w=$param2&i=$param3>$body</A> <pre>
        

        Could this be a bug?

        1. Jan 13, 2006

          David Loeng says:

          Even with multiple parameters the first parameter is still $param0 on testing in...

          Even with multiple parameters the first parameter is still $param0 on testing in Confluence 2.1.2.

          That is, the following macro:

          first: not shown, second: $param1, third: $param2
          

          When called like this:

          {test:foo|bar|baz}
          

          gives:

          first: not shown, second: bar, third: baz
          

          Cheers,
          Dave

          1. Jan 14, 2006

            Othman Alaoui says:

            You're right David. User error. Thanks for checking.

            You're right David. User error. Thanks for checking.

  10. Jan 26, 2006

    Mark Michaelis says:

    Hello, I need to have a way to decide whether a page is exported as PDF or not....

    Hello,

    I need to have a way to decide whether a page is exported as PDF or not. I thought I might use $action.isPrintableVersion() but this seems to return false for PDF generation. Does anyone know any other way to do this?

    Regards,
    Mark

    1. Feb 02, 2006

      Tom Davies says:

      There isn't any way to do this at present, but in 2.1.4 you will be able to do: ...

      There isn't any way to do this at present, but in 2.1.4 you will be able to do:

      #if ($renderContext.outputType == "pdf")
      I'm a PDF
      #else
      c'est ne pas un PDF
      #end

      Tom

  11. Feb 08, 2006

    Cheryl Chase says:

    I'm using the technique I learned on this page to fetch a numeric value from a d...

    I'm using the technique I learned on this page to fetch a numeric value from a database, like this:

    #set( $query = "{sql:jndi=Reports |heading=false| table=false}select $param0 from metrics where year=$param1 and ticker='${content.realTitle}'{sql}")
    
    #set($globalHelper=$action.getGlobalHelper())
    
    #set($renderedContent=$globalHelper.renderConfluenceMacro($query))
    ${renderedContent}
    

    The value is returned, but it comes back with leading and trailing newlines. This is a problem, because sometimes I want to follow the value with a "%", as follows. I can't put the "%" inside the macro, because not all invocations of the macro want the "%".

    {metric:expense_ratio|2005}%
    
    produces:
    
    0.015 %
    
    

    I've tried trim and replace functions, to no avail (but perhaps I didn't invoke them correctly; I am not a java programmer). Trim seems to ignore the newlines, and when I did $globalHelper.renderConfluenceMacro($query).replace("\n",""), the macro returned "${renderedContent}" (that is, the literal variable name, not the rendered content!)

    Can someone show me how to trim these newlines?

    1. Feb 08, 2006

      Tom Davies says:

      I would expect $globalHelper.renderConfluenceMacro($query).trim()   to ...

      I would expect

      $globalHelper.renderConfluenceMacro($query).trim()
      

       

      to work.

      Or

      $globalHelper.renderConfluenceMacro($query).replaceAll("\n","")
      

      replace() expects characters rather than strings, so the code you used above coulsn't find a function to call.

  12. Feb 09, 2006

    Cheryl Chase says:

    For some reason, replaceAll("\n","") seem to work. Here's my code and the outpu...

    For some reason, replaceAll("\n","") seem to work.

    Here's my code and the output (I've put "x" on either side of \${renderedContent} in the macro, to make more obvious the source of the unwanted space):

    Macro Source
    
    #set( $query = "{sql:jndi=Reports |heading=false| table=false}select $param0 from metrics where year=$param1 and ticker='${content.realTitle}'{sql}")
    
    #set($globalHelper=$action.getGlobalHelper())
    
    #set($renderedContent=$globalHelper.renderConfluenceMacro($query).replaceAll("\r",""))
    
    
    x${renderedContent}x
    
    Page Source (WIKI markup)
    
    | Expense Ratio | {metric:expense_ratio|2005}% |
    
    
    OUTPUT (in browser)
    
    x0.00x %
    
    VIEW SOURCE (in browser)
    
    
    
    
    x0.00x
    % 
    
  13. Feb 09, 2006

    Cheryl Chase says:

    I think that the position of the "x" characters in the above make clear that the...

    I think that the position of the "x" characters in the above make clear that the unwanted newline is not in the result of $renderedContent=$globalHelper.renderConfluenceMacro($query), so no manipulation of $renderedContent is going to help. For some reason, the user macro execution process is adding newlines to what I want to return.

    Is there some sort of a context that I can manipulate, to tell it that my output is inline?

    1. Feb 09, 2006

      Guy Fraser says:

      Not easily. There's some CSS hacks you can use, eg: <span class="inline">...

      Not easily. There's some CSS hacks you can use, eg:

      <span class="inline"> rest of macro output here </span>
      

      Then use following CSS:

      span.inline {
      display: inline !important;
      }
      

      Or something along those lines. However, it seems that MSIE doesn't cope well with this (or anything else really, I do wish they'd hurry and get IE 7 out as then web development will be significantly easier as everything runs to one standard).

      The only reliable way we've found is to create a java plugin version of the macro. Fairly easy to do, but a complete pain when all you want is a quick user macro.

      Ideally, we need an "Display inline" checkbox when creating a user macro - there are vast numbers of cases when people want to display just some inline text or whatever, but can't because it gets wrapped in <p> tags by default. For example, you might want a common thing like company name, email address, product name, etc., to be ouput by a user macro = ensures consistency across a big site and also allows you to easily update in one place at a later date. However, the lack of inline ability for user macros (even if you try digging in to the API from them there is still no joy) thwarts every attempt.

      1. Feb 09, 2006

        Tom Davies says:

        I've raised an issue: http://jira.atlassian.com/browse/CONF-5456
        1. Sep 14, 2006

          Steve Hart says:

          The issue says that it is resolved, but unfortunately only for macros which have...

          The issue says that it is resolved, but unfortunately only for macros which have a body. I am writing a small macro to create a link to a particular space, and I want it to render after I create the link (so that it will insert the "create page" in the case that the link target doesn't already exist (it is for an acronym space). So my macro doesn't have a body (i.e. {acronym:TLA}) I really don't want it to have to have a body (unecessary typing for my users). So I would still like to see and "Inline" checkbox.

           In the meantime, I used this, which is awkward, but works on both IE and firefox:

          #set($renderedContent=$renderer.convertWikiToXHtml($context,"[$param0|ACRO:$param0]"))
          #set($renderedContent=$renderedContent.replaceAll("<p>",""))
          #set($renderedContent=$renderedContent.replaceAll("</p>",""))
          ${renderedContent}
          
          1. Sep 14, 2006

            James Mortimer says:

            I use this. Equally awkward, but with the added features of: works in template...

            I use this. Equally awkward, but with the added features of:

            • works in templates, preview or page views
            • has a friendly 'hover text' indicating that you will navigate to a new space
            • replaces only leading/training <p> tags, not all <p> tags, which isn't important in this use case but helps with other render tasks
              #set($wiki="[$param0|HELP:$param0]")
              #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))
              #else ## we are e. g. in Global Template Preview
              #set($xhtml=$globalHelper.renderConfluenceMacro($wiki))
              #end
              ## 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
              #set($xhtml=$xhtml.replaceAll("title=\"$param0\"","title=\"Look up \'$param0\' in the Help space.\""))
              ${xhtml}
              
            1. Apr 25

              Stefanus Du Toit says:

              I raised another issue for this: CONF-15333. I included your workaround in the ...

              I raised another issue for this: CONF-15333.

              I included your workaround in the comments (thanks for providing it) but I really think this should be fixed in confluence. I think there was some confusion in CONF-5456 that caused the issue to be resolved when it wasn't really properly resolved.

  14. Apr 12, 2006

    James Mortimer says:

    Am I useless, or is the API documentation? I was trying to find a function...

    Am I useless, or is the API documentation?

    I was trying to find a function like 'getparent' or 'getchildren' and could find absoluteley no mention of it in the API docs for the objects listed above. However, on a last-ditch whim, I tried:

    #set($result=$content.getParent())
    $

    Unknown macro: {result}

    #set($result=$content.getChildren())
    $

    and to my amazement and horror, they both worked.

    So is there any REAL API documentation around, or am I completely missing something in the documentation linked above?

    1. Apr 12, 2006

      James Mortimer says:

      Should have used {code} tags #set($result=$content.getParent()) ${result} #...

      Should have used {code} tags

      #set($result=$content.getParent())
      ${result}
      #set($result=$content.getChildren())
      ${result}
      
      1. Apr 12, 2006

        David Peterson [CustomWare] says:

        Whilst there are definitely still holes in documentation surrounding Confluence,...

        Whilst there are definitely still holes in documentation surrounding Confluence, in this case there is a description of the variables available and links to their API documentation listed in the available objects section above. It lists the variable and gives a link to the API docs for that object (in this case, $content and ContentEntityObject).

        1. Apr 12, 2006

          David Peterson [CustomWare] says:

          Ah...sorry just reread your original post and now get what you're on about. Cont...

          Ah...sorry just reread your original post and now get what you're on about. ContentEntityObject is the abstract base class for a few different types of content, including BlogPost, Comment, SpaceDescription and of course Page. The only one of those which allows a parent/child hierarchy is Page, which is why there is no 'getParent()' method in ContentEntityObject. So, the macro you have above will only work on pages - if you use it in a blog post or a comment it will throw an exception. To make sure it doesn't break on other types of content, you could add a test, something like the following:

          #if ($content.type == "page")
          #set($result=$content.getParent())
          ${result}
          #set($result=$content.getChildren())
          ${result}
          #end
          
        2. Apr 13, 2006

          James Mortimer says:

          Thank you, David. That is precisely the page that I am looking at, and I find ab...

          Thank you, David. That is precisely the page that I am looking at, and I find absolutely no mention therein of a getParent() or getChildren() methods.  What am I missing?

          1. Apr 13, 2006

            James Mortimer says:

            I replied to quickly without seeing your second comment. I wish I could delete c...

            I replied to quickly without seeing your second comment. I wish I could delete comments from here.

            I can see now the connection.

            My problem was that I was looking at the 'PageContentEntityObject' subclass of the 'ConentEntityObject' and for some reason 'AbstractPage' is actually subclass of 'SpaceContentEntityObject' and 'Page' is a subclass of 'AbstractPage'. I was only looking down the 'pagecontententityobject' branch.

            Is there a better way to navigate the API to find out the relationship between Page, AbstractPage, ConfluenceEntityObject, etc....?

             Anyway, answer to my original question is, as I expected, that it was me that was useless.  THanks for your help.

            1. Apr 13, 2006

              David Peterson [CustomWare] says:

              Yeah, the PageContentEntityObject threw me for a minute too when I was looking a...

              Yeah, the PageContentEntityObject threw me for a minute too when I was looking at the API again - I think the idea is that subclasses of PageContentEntityObject are content which belongs to a Page, while SpaceContentEntityObject subclasses are for content that belongs to a Space...

              As for a better way to navigate the API, there are none that I'm aware of. Learning how to walk the paths of Confluence have been a combinaton of trial-and-error and asking lots of questions. It's a complex application, built on several layers of foundation, which makes it hard to dig into sometimes. On the up-side, JIRA is worse

  15. Apr 24, 2006

    Troy McKinnon says:

    Anyway to create link using a custom page template using a user macro? An attem...

    Anyway to create link using a custom page template using a user macro?

    An attempt at hacking it in for instance. Sort of works but doesn't pick up the template name.

    <a href="/confluence/pages/createpage-entervariables.action?spaceKey=$space&parentPageId=${param0}&fromPageId=${param0}&title=${param1}&linkCreation=false&templateName=Status%20Report">New Status Report</a>
    

    Usage:

    {new_status_report:1234|Status Report 2006-04-05}
    
    1. Apr 24, 2006

      Guy Fraser says:

      The create page macro might do what you are after as you can pre-define prefix a...

      The create page macro might do what you are after as you can pre-define prefix and postfix for the page title, and if no page title is specified, the user is asked to enter one.

      http://confluence.atlassian.com/display/CONFEXT/Create+Page+Macro

    2. Apr 25, 2006

      James Mortimer says:

      to 'hack' the url and supply a template properly, you require a template ID. See...

      to 'hack' the url and supply a template properly, you require a template ID. See the create-page macro mentioned below.  Also, the linking plugin works well in most cases.

  16. May 09, 2006

    Artyom Borodkin says:

    How to enumerate all registered user and get their full names? #set($users=$...

    How to enumerate all registered user and get their full names?

    #set($users=$content.getUserAccessor().getUsers() )
    #foreach($user in users)
     $user.name
    #end
    

    The code above doesn't work

    1. May 09, 2006

      Dan Hardiker says:

      The property you want is "fullName" so the following may work better: #set($us...

      The property you want is "fullName" so the following may work better:

      #set($users=$content.getUserAccessor().getUsers() )
      #foreach($user in users)
       $user.fullName
      #end
      
      1. May 09, 2006

        Artyom Borodkin says:

        Unfortunately the enumeration doesn't work at all. Seems like The getUsers() ret...

        Unfortunately the enumeration doesn't work at all.
        Seems like The getUsers() returns an empty array.

        1. May 11, 2006

          James Mortimer says:

          Are you using LDAP or another external user authentication system? I think if yo...

          Are you using LDAP or another external user authentication system? I think if you are using LDAP for your user authentication, .getUsers() returns an empty array.

      2. Nov 13, 2006

        Jeff Guthrie says:

        How can i just find the username of the currently logged in user?  this is ...

        How can i just find the username of the currently logged in user?  this is the code I have write now:

         #set($user = $userAccessor.getUser())
        
        $user
        
        1. Nov 13, 2006

          Tom Davies says:

          $user.name

          $user.name

          1. Nov 14, 2006

            Jeff Guthrie says:

            If I have this code in a macro called currentuser: #set($user = $userAccessor.g...

            If I have this code in a macro called currentuser:

            #set($user = $userAccessor.getUser())
            
            $user.name
            

             and on my page, I put this code: 

            Unknown macro: {currentuser}

            , what prints on the page is

            $user.name

            So it is not working quite yet...  I would also like to have this working on each page without manually putting the macro on each page...

            1. Nov 15, 2006

              Ivan Benko says:

              Hi Jeff, here is a small usermacro that gives you information about the current ...

              Hi Jeff,
              here is a small usermacro that gives you information about the current user.
              Get the $user object first and then obtain:
              fullName - full name of an user
              email - user's email (if exists)
              name - user's login name

              #set($user=$action.remoteUser)

              $user.fullName
              $user.email
              $user.name

              1. Nov 16, 2006

                Jeff Guthrie says:

                Oh thats how you do it, thanks!  Where can i find other properties I ca...

                Oh thats how you do it, thanks!  Where can i find other properties I can grab about the current user or other info?  (using $action.???  or $user.browsertype? etc...)

                Thanks!

                1. Sep 14, 2007

                  Martijn Danse says:

                  It would interesting (but perhaps unsafe) if we could obtain the users password ...

                  It would interesting (but perhaps unsafe) if we could obtain the users password through this. This could solve the problem with the Jira bug lists in Confluence when anonymous access is off. Is this possible?

                  1. Sep 17, 2007

                    Fennie Ng says:

                    Hi Martin, If you are keen on this feature, I would suggest you to raise a feat...

                    Hi Martin,

                    If you are keen on this feature, I would suggest you to raise a feature request for this at our JIRAissue tracker.

                    Regards,
                    Fennie

              2. Jan 28, 2007

                Andrew Whyte says:

                This is great to know. Quick question however, is the use of $action.remoteUser...

                This is great to know.

                Quick question however, is the use of $action.remoteUser security safe?. i.e to find the current user, does this use a call to return the sessions authenticated user, or does it simply extract the name from a cookie or something silly?

                From what I can tell it's using a call through authenticated user or something involving the session info, so it should be safe against someone seeding a username in a form with a REMOTE_USER value. ??

                I only ask because I want to be sure I can use it in a certain way.

                1. Jan 28, 2007

                  Dan Hardiker says:

                  $action.remoteUser returns you the Atlassian User "User" object that has been pr...

                  $action.remoteUser returns you the Atlassian User "User" object that has been properly authenticated through the session. It's not a String value and cannot be spoofed by simply passing through a variable in the headers or in the URL.

                  The only realistic way I can think of to change user, is to log packet data coming from the confluence server and then hijack the session for the appropriate user. Using SSL would remove that option though.

                  Knowing most users - it would probably be easier just to shoulder surf, or even just bribe them with chocolate.

  17. Jul 10, 2006

    jd lima says:

    Any have a tip how to access the tiny link – e.g., "http://confluence.atla...

    Any have a tip how to access the tiny link – e.g., "http://confluence.atlassian.com/x/hRE" – for the current page within a user macro? Thanks!

    1. May 18, 2007

      James Mortimer says:

      I'm also interested in this; it was done in a macro: {page-info:tinyurl} and...

      I'm also interested in this;

      • it was done in a macro: {page-info:tinyurl}
      • and I can get a page url in a user macro:
        • $action.getGlobalSettings().getBaseUrl()$content.getUrlPath()
      • but not a tiny url. This requires a 'new' object, TinyUrl, be created which can't be done in velocity unless there is an available object to return one. I can't see how to get from $content to TinyUrl()
  18. Jul 27, 2006

    Steve Soskin says:

    Is there any way to change the text color/size of just the title line in the pan...

    Is there any way to change the text color/size of just the title line in the panel macro?

    thnx,

    steve

    1. Jul 27, 2006

      David Loeng says:

      You will need to modify the panelHeader class in the CSS file (confluence/WEB-IN...

      You will need to modify the panelHeader class in the CSS file (confluence/WEB-INF/classes/styles/site-css.vm).

      Cheers,
      Dave

      1. May 27, 2008

        Anonymous says:

        I have modified the panelHeader class in the CSS file site-css.vm to include a l...

        I have modified the panelHeader class in the CSS file site-css.vm to include a line...

        color: white;

        But when I use firebug to inspect the area that should have the white text, the css shows the color parameter crossed out.

        I am using Theme Builder 3.x and at one time I had this working using the same css within a style macro but it is no longer working.

        I tried adding it to the Theme Builder CSS for the Layout but that didn't work either.  Any suggestions?

        1. Jun 02, 2008

          Tony Cheah Tong Nyee says:

          Hi there, The suggestion is applicable to only the "Default Theme". If you are ...

          Hi there,

          The suggestion is applicable to only the "Default Theme". If you are using other theme than the default, you may need to look into the associated CSS file of the particular theme.
          If you are using the Theme Builder, I would suggest you to seek assistance from the author at the plugin's Issue Tracker:

          Cheers,
          Tony

  19. Sep 28, 2006

    dieter says:

    Some questions about usermacros: 1. What's the function to add a label to a pag...

    Some questions about usermacros:

    1. What's the function to add a label to a page? I want to add an unique automatically generated label to a page to use in template, by writing an usermacro. With add-label macro you can't do this.

    I have

     
    #set($pageId=$content.getIdAsString()) 
    #set($labelmanager=$action.getLabelManager())
    #set($result = $labelmanager.addLabel($content,new Label("test$pageId")))
    

    but doesn't work. A counter would be better than the pageId, but is it possible to store a variable on a page? So for each new added page the counter does +1: test1, test2, test3, test4, ..?

    Thanks a lot.

    2. The function to get the templateID if you know the templatename?

    1. Oct 30, 2006

      Matt Ryall (Atlassian) says:

      1. There's no way to add a new label from within a user macro, because you can't...

      1. There's no way to add a new label from within a user macro, because you can't create new objects in Velocity. You'll need to write a macro plugin to do this.

      2. The PageTemplateManager is responsible for this. The method is getPageTemplate(String name, Space space), where you pass a null space for a global template. However, you can't access this object from user macros either, so you'll need to write a macro plugin if you want to do this.

      The Velocity context for user macros only includes objects used for common operations. Including all the Confluence managers would make page rendering slower and consume more memory. Macro plugins allow full access to everything inside Confluence, and are not difficult to get working with a small bit of Java knowledge.

  20. Nov 16, 2006

    Tami Shaw says:

    I'm a little confused on how to use the New Code Macro with Javascript. On many...

    I'm a little confused on how to use the New Code Macro with Javascript.

    On many of your Macro pages, there is a Version area within a table that has the ability to expand or hide info for each version. (hide-desc, show-desc)...There's no macro in the confluence library that does this and the page tree plug in is for different pages. I can't seem to get the New code one to work though. Could someone show me an example of how something like this is done or used.

  21. Apr 12, 2007

    David Bailie says:

    I'm using a simple macro to automatically generate a link to a url. Here is the...

    I'm using a simple macro to automatically generate a link to a url. Here is the content of my macro:

    [JIRA #$param0|http://jira.mycompany.com/browse/$param0]
    

    This works fine except the url is in a <p> block in the generated code, so if I want to use this in line it causes carriage returns around the link.

    Here is a sample of my wiki markup on one page:

    This is a link to {jira:XX-123} using a macro and all of this should be on one line.
    
    This is a link to [JIRA #123|http://jira.mycompany.com/browse/XX-123] not from a macro.
    

    Here the html source of the resulting page:

    <p>This is a link to </p><p><span class="nobr"><a href="http://jira.mycompany.com/browse/XX-123" rel="nofollow">JIRA #123<sup><img class="rendericon" src="/images/icons/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span></p> using a macro and all of this should be on one line.<p></p>
    
    <p>This is a link to <span class="nobr"><a href="http://jira.mycompany.com/browse/XX-123" rel="nofollow">JIRA #123<sup><img class="rendericon" src="/images/icons/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span> not from a macro.</p>
    

    Which looks like this:
    This is a link to

    JIRA #123

    using a macro and all of this should be on one line.

    This is a link to JIRA #123 not from a macro.

    1. Apr 12, 2007

      David Bailie says:

      BTW, my specific question is, how can I prevent the macro from adding the extra ...

      BTW, my specific question is, how can I prevent the macro from adding the extra <p> tags around the link.

       Thanks.

      1. Apr 12, 2007

        David Bailie says:

        Using HTML code in the macro instead of wiki markup seemed to do the trick. ...

        Using HTML code in the macro instead of wiki markup seemed to do the trick.  Something like:

        <a href="http://jira.mycompany.com/browse/$param0">JIRA #$param0</a>
        

        but I would expect to be able to do this with wiki markup as well...

        Note that with the above I do loose the cute little arrow icon etc which I'm sure I could also add manually in the html code if I wanted.

  22. Apr 25, 2007

    Ari Christakis says:

    If I edit site-css.vm, it crashes confluence on the server.  I have disable...

    If I edit site-css.vm, it crashes confluence on the server.  I have disabled velocity caching.  Any thoughts?

    1. May 21, 2007

      Rosie Jameson [Atlassian Technical Writer] says:

      Please log a support request at http://support.atlassian.com -- thank yo...

      Please log a support request at http://support.atlassian.com -- thank you

  23. May 22, 2007

    Leo Yankulin says:

    Hello. I'd like to implement "term" user macros that behaves much like metadata ...

    Hello. I'd like to implement "term" user macros that behaves much like metadata macro but displays a tooltip when mouse is over the "term". Its definition should be smth. like
    {term:WMP}Windows Media Player{term}
    . Later, user can define
    {term-show:WMP}
    and get WMP displayed with some marking, so reader can point a mouse on it and get a tooltip saying "Windows Media Player". I am not sure that such macro is already exist.

    If you know about a macro doing it, please let me know. Otherwise, please guide me how i can display a tooltip like window using Velocity.

    Thank you.

    1. May 22, 2007

      Rosie Jameson [Atlassian Technical Writer] says:

      Please try posting this question in the Confluence forum: http://forums.atlassia...

      Please try posting this question in the Confluence forum: http://forums.atlassian.com -- thank you

  24. Aug 09, 2007

    Jeremy Largman says:

    It's a pretty common request. Here's another way to do it: #set($username=$ac...

    It's a pretty common request. Here's another way to do it:

    #set($username=$action.getRemoteUser().getName())
    $username
    
  25. Sep 11, 2007

    Anonymous says:

    Hi, I want to create a macro that prints the current date along with the macro ...

    Hi,

    I want to create a macro that prints the current date along with the macro body - so something like |somemacro| body goes here |somemacro|

    should output

    body goes here  09/11/2007 5:37 PM

    This date only should be printed once - not updated with every edit of the page. I can get the page modified time but that will update on every page edit.

    1. Sep 12, 2007

      James Mortimer says:

      you want a wikipedia-like signature, which requires updating the page content di...

      you want a wikipedia-like signature, which requires updating the page content directly, not a user macro.

      • can't do it from a user macro, they are for 'display' only
      • look at the 'sub-section' or 'refactoring' plugins for examples of code to create this sort of thing.
  26. Sep 17, 2007

    Jonathan Simonoff says:

    Is there a way to get the content of a page (other than the current page) from i...

    Is there a way to get the content of a page (other than the current page) from inside a macro?  (I'd like to at least initially do this in a user macro, but if I need to write a real plugin, I can do that--however, from looking at the docs and the objects available, I don't see any methods that let you specify a page and space and get back the contents.)

    1. Sep 18, 2007

      Tony Cheah Tong Nyee says:

      Hi Jonathan, To my understanding, you wish to display the content of a specific...

      Hi Jonathan,

      To my understanding, you wish to display the content of a specific page onto another page. If this is the case, you may wish to use the Include Page macro which enable one to include the content of a defined page onto another.
      If the above is not an option, a suggestion that I can think of is to build a plugin of your own which would serve the purpose. Sorry to say that, this cannot be done using the User macro due to the limitation of the available objects.

      Cheers,
      Tony

      1. Sep 18, 2007

        Jonathan Simonoff says:

        Thanks, Tony. I don't want to print the entire content of the other page like t...

        Thanks, Tony.

        I don't want to print the entire content of the other page like the include page macro would, but to extract part of that page programmatically and display that.  (FYI, this is for a feature that I'm trying to convert from our previous wiki that extracts definitions from a glossary page.)

        So it sounds like I need to write a real plugin.  

        1. Sep 18, 2007

          James Mortimer says:

          yes and no. A real plugin would be more robust and safer, and probably more perf...

          yes and no. A real plugin would be more robust and safer, and probably more performant...but take longer to prototype

          • look at the edit-include user macro
          • it is a user macro that uses an internal renderer to call 'include', and then based on a simple parsing of the result decide whether to show the result, or render a different macro.
          • you could use the built in java string API to do some pretty sophisticated parsing if you want to, instead of just looking for an error message as I have done.
          1. Sep 21, 2007

            Jonathan Simonoff says:

            James, that is exactly what I was looking for. Thanks a lot!  (And, BTW...

            James, that is exactly what I was looking for. Thanks a lot!  (And, BTW, that edit-include functionality is great!)

  27. Sep 28, 2007

    Jonathan Simonoff says:

    Does anyone know how to do a $string.replaceAll (or equivalent) with DOTALL in e...

    Does anyone know how to do a $string.replaceAll (or equivalent) with DOTALL in effect, I mean so that . matches anything, including newlines?

    That is:

    $body.replaceAll(".*","got the whole thing")
    

    if given a multi-line body, will put "got the whole thing" once for each line.  The behavior I need is to replace the entire contents of the body, even if there are newlines in there.

    1. Oct 01, 2007

      James Mortimer says:

      didn't have time to test it or check the syntax, but if you use REGEX directives...

      didn't have time to test it or check the syntax, but if you use REGEX directives, perhaps:

      $body.replaceAll("(?si:.*)","got the whole thing")
      

      flags:
      s - treat as single lines, i.e. newline is a character
      i - case insensitive match
      m - treat as multiple lines, i.e. break on newline

      these are normally used outside the expression in perl, i.e. "s/.*/text/si", but not java.

  28. Oct 02, 2007

    Jag Gill says:

    HI all - Does anyone have any ideas on how to use the useraccessor to pull back...

    HI all -
    Does anyone have any ideas on how to use the useraccessor to pull back ldap information in a user macro? We are using Active Directory and I want to be able to pull back various properties of the user, such as manager and department.
    Many Thanks
    Jag

    1. Oct 03, 2007

      Tony Cheah Tong Nyee says:

      Hi Jag, Did you mean that you would like to be able to retrieve other user info...

      Hi Jag,

      Did you mean that you would like to be able to retrieve other user information from the LDAP server such as phone numbers, addresses and other attributes? Unfortunately, Confluence does not support this. Having that said, there is no methods provided in the UserAccessor class that is able to retrieve the additional information from the LDAP server.
      However, you may be interested look at the following improvement request regarding improving our Atlassian User to be able to retrieve additional data:

      Feel free to cast your vote to increase its popularity and add yourself as a watcher so that you will be notified if there are any updates to the issue. Also, you may add comments to improvement issue to truly reflect the importance of the feature to you.

      Cheers,
      Tony

  29. Oct 19, 2007

    Darcy Max says:

    Hi, We add usernames as labels on pages to indicate what users in our community ...

    Hi,
    We add usernames as labels on pages to indicate what users in our community need to take action on a page. I wanted to add a 'contentbylabel' macro to all spaces that would reflect what the signed-in user needed to address in that space, based on their username. For example:

    contentbylabel:@user | key=@self

    Unfortunately, Confluence does not support the feature in this macro. Does anyone know how to create a user macro that will do this?

    Many thanks,

    Darcy 

    1. Oct 25, 2007

      Tony Cheah Tong Nyee says:

      Hi Darcy, Indeed, the contentbylabel macro does not provide such parameter that...

      Hi Darcy,

      Indeed, the contentbylabel macro does not provide such parameter that meets your requirement.

      that would reflect what the signed-in user needed to address in that space, based on their username.

      You may be interested to look at the getRemoteUser() method available in the ConfluenceActionSupport class (the $action object) to see if it helps.

      Cheers,
      Tony

  30. Dec 18, 2007

    Thomas Schweikle says:

    I am trying to add a macro showing a table of content using the toc-macro, but p...

    I am trying to add a macro showing a table of content using the toc-macro, but packed into a box:

    <div class='panelMacro'>
    <table class='infoMacro' width="100%">
    <tr>
    <td>
    <h2>Seiteninhalt:</h2>
    {toc}
    </td>
    </tr>
    </table>
    </div>
    

    This shows prints {toc} if I set "macro generates HTML". If I set "macro generates wiki markup" I am looking at html codes surrounding my table of content.

    Any idea how I could get what I'd like to have: the table of content inside a box?

    1. Dec 18, 2007

      Gilad David Maayan says:

      Use a macro with a body, and insert $body where you currently have . That turn...

      Use a macro with a body, and insert $body where you currently have

      . That turns it into a macro that puts anything in a box. For a toc, just type:

      {mymacro}{toc}{mymacro}
      1. Dec 18, 2007

        Thomas Schweikle says:

        Yes, that would be a soultion, but — since I want the users to include onl...

        Yes, that would be a soultion, but — since I want the users to include only one macro like {mytoc}. I could get it if I define two macros: one to generate the box and one to generate wiki markup, but this leaves a door open to access an intermediate macro, users not intended to use!

        How can I write a macro doing both: expand wiki markup and html?

    2. Dec 18, 2007

      James Mortimer says:

      There are two other ways use wiki markup instead of HTML for the div and table...

      There are two other ways

      • use wiki markup instead of HTML for the div and table tags, and select 'macro generates wiki markup'
      • create and use a render velocity template macro as follows
        <div class='panelMacro'>
        <table class='infoMacro' width="100%">
        <tr>
        <td>
        <h2>Seiteninhalt:</h2>
        #render("{toc}")
        </td>
        </tr>
        </table>
        </div>
        
      • the contents of the render macro can be found here: render wiki markup from a user macro
      1. Dec 18, 2007

        James Mortimer says:

        We do a similar thing to generate a default 'formatting' for our toc Macro: {con...

        We do a similar thing to generate a default 'formatting' for our toc
        Macro: {contents}
        body: no
        output: Macro generates wiki markup

        ## Generate a table of contents, right justified and in a green box
        {float:right|width=300px|background=#E0F0F0}{*}Table of Contents{*}{toc}{float}
        
        1. Jul 14, 2008

          Anonymous says:

          Hi, I'm in the same situation with wanting to format a div box around the TOC m...

          Hi,

          I'm in the same situation with wanting to format a div box around the TOC macro.

          I tried several attempts at using the included 'class' option that TOC has, and can successfully create and format a div as desired.  However, my problem is that the macro does not accept any CSS formats that I try to apply to the list items (list-style-type= square) for example.

          Here is the css:

          .test
          {
          border: thin solid red;
          list-style-type: square;
          }
           

          Which results in a red outlined div, but with the default 'disc' type instead of the 'square'.  The class formatting only applies to the div element, and nothing below that.

          I have also tried doing the suggestions above, but I cannot get a macro within a macro to work either.  Any help would be greatly appreciated!

          Drak.

          1. Jul 15, 2008

            James Mortimer says:

            I'd take this question to the TOC macro page

            I'd take this question to the TOC macro page

  31. Dec 20, 2007

    Anonymous says:

    Hi, Can anyone suggest how to retrieve a page by it's name and space key? The f...

    Hi,

    Can anyone suggest how to retrieve a page by it's name and space key? The following macros code certainly does not work:

    #set($temp=$pageManager.getPage("SPACEKEY", "PAGETITLE"))
    $temp
    

    Retrieving page by id does not work as well.

    Retrieving user works perfectly.

    Thanks in advance!

    1. Jan 01, 2008

      Tony Cheah Tong Nyee says:

      Hi there, You may be interested to look at the following documentation that out...

      Hi there,

      You may be interested to look at the following documentation that outlined a list of the objects that can be used in user macros:

      For further information regarding the methods available from the objects, please see our latest Confluence's API.

      Also, the following classes extracted from the API may serve as a reference to you:

      Ideally, if you have further questions regarding customizing Confluence, you can share them in our forums or mailing list, as the users/developers there who have experience in similar issue might share their idea with you.

      Cheers,
      Tony

  32. Jan 29, 2008

    Jonathan Simonoff says:

    I'm trying to write a user macro that can do stuff with the page's children, and...

    I'm trying to write a user macro that can do stuff with the page's children, and it seems like I need to get the Page object in order to get the children. It seems like this should work:

    #set($globalHelper=$action.getHelper())
    #set($page=$globalHelper.getPage())
    $page.getChildren()
    

    But $page never seems to get set to anything. ($page.getChildren() just prints literally.)

    (Two FYIs: I know I could just use a "children" macro to print this--I'm going to collect the children list and process it in the macro. Also, I can see this kind of thing would be better done in a plugin, but I'm trying to prototype this.)

    Thanks! Jonathan

    1. Feb 12, 2008

      Tony Cheah Tong Nyee says:

      Hi Jonathan, You may be interested to look into the $content object which is al...

      Hi Jonathan,

      You may be interested to look into the $content object which is also supported in user macro. Having said that the Page object's methods are accessible if the $content object is being used.

      Cheers,
      Tony

  33. Feb 20, 2008

    Chris Worth says:

    Does anyone know how to get an instance of the spaceManager and/or pageManager f...

    Does anyone know how to get an instance of the spaceManager and/or pageManager from within a user macro?

    Specifically, I'm trying to retrieve the blogposts (news items) for a space. The Space object is available, but its method "getBlogPosts" is listed as deprecated, along with the note " use spaceManager.getBlogPosts(space, false) instead". 

    The Action object available appears to be a concrete instance of ConfluenceActionSupport, as opposed to one of its subclasses such as ViewPageAction, which does appear to have methods to retrieve the space/pageManagers.

    Any help would be greatly appreciated!

    1. Feb 21, 2008

      Choy Li Tham says:

      Hi Chris, To my understanding, for Confluence version 2.3 and later, it is advi...

      Hi Chris,

      To my understanding, for Confluence version 2.3 and later, it is advisable to use the "PageManager.getBlogPosts(Space, boolean)" instead of using the "SpaceManager.getBlogPosts(Space, boolean)"in the "getBlogPosts" method. You may want to give a try by using the "PageManager.getBlogPosts(Space, boolean)" method in a user macro and see if it helps. For more information regarding the methods available for the SpaceManager, the following documentation may serve as a reference to you:

      Meanwhile, if you have any queries regarding Confluence customization, I would suggest you to post your queries to our forum or mailing list. From there, others developer/user who have experience on this customization should be able to share their ideas with you.

      Regards,
      Choy Li

  34. Mar 03, 2008

    Hugh Dolden says:

    How do I write a VM that iterates through a list passed as a parameter. i.e. ...

    How do I write a VM that iterates through a list passed as a parameter.

    i.e.

    
    {mymacro:["a","b","c"]}
    
    #foreach ($y in $param0)
      <tr><td>$y</td></tr>
    #end
    
      <tr><td>a</td></tr>
      <tr><td>b</td></tr>
      <tr><td>c</td></tr>
    
    
    1. Mar 03, 2008

      Choy Li Tham says:

      Hi Hugh, I would suggest you to post your queries to our forum or mailing list....

      Hi Hugh,

      I would suggest you to post your queries to our forum or mailing list. From there, others developer/user who have experience in velocity should be able to share their ideas with you.

      Regards,
      Choy Li

  35. Mar 04, 2008

    Alexander Schinko says:

    When is the core api documentaton online again? I get an error 500.

    When is the core api documentaton online again? I get an error 500.

    1. Mar 04, 2008

      Mei Yan Chan says:

      Hi Alexander, I have raised this issue with our system administrators and they ...

      Hi Alexander,

      I have raised this issue with our system administrators and they are currently looking into it. If you still aren't able to access the site by tomorrow, please send us a report at the link below:

      Sorry for the inconvenience.

      Regards,
      Mei

    2. Mar 07, 2008

      Jonathan Simonoff says:

      FYI, I just got the info that the API docs are now at http://docs.atlassian.com/...

      FYI, I just got the info that the API docs are now at http://docs.atlassian.com/atlassian-confluence/2.7/

      1. Mar 28, 2008

        Brian M. Thomas says:

        And what about the 2.5 javadocs?

        And what about the 2.5 javadocs?

        1. Mar 30, 2008

          Choy Li Tham says:

          Hi Brian, The API docs for Confluence 2.5 is available at the following link: ...

          Hi Brian,

          The API docs for Confluence 2.5 is available at the following link:

          Regards,
          Choy Li

  36. Mar 27, 2008

    Jens Schumacher says:

    To embed content from another site into Confluence you can use iFrames. However,...

    To embed content from another site into Confluence you can use iFrames. However, since Confluence doesn't allow arbitrary html tags in the wiki markup, this is a prime candidate for user macros:

    Name: iframe
    Macro has body: no
    Template: <iframe src="$src" width="$width" height="$height"></iframe>

    Usage:
    {iframe:src=http://google.com |height=400px|width=800px}

    1. Apr 02, 2008

      Anonymous says:

      This *does not work* in my install of Confluence 2.7.3. It must have bee...

      This *does not work* in my install of Confluence 2.7.3. It must have been a security fix.

      1. Apr 02, 2008

        David Peterson [CustomWare] says:

        I wasn't aware you could use named parameters in user macros. Also, I don't thin...

        I wasn't aware you could use named parameters in user macros. Also, I don't think you can specify 'px' in dimensions on width/height. Try this instead:

        Name: iframe
        Macro has body: no
        Template: <iframe src="$param0" width="$param1" height="$param2"></iframe>

        Usage:

        {iframe:http://google.com/|800|400}
        
        1. Apr 02, 2008

          David Peterson [CustomWare] says:

          Upon testing, it seems that the <iframe> is output, but it has no attribut...

          Upon testing, it seems that the <iframe> is output, but it has no attributes. Very odd behaviour really...if it was for security, why not remove the <iframe> altogether?

          1. Apr 03, 2008

            James Mortimer says:

            yeah, that's weird. not seeing this behaviour on 2.5.7.

            yeah, that's weird. not seeing this behaviour on 2.5.7.

        2. Apr 03, 2008

          James Mortimer says:

          you can use named parameters in user macros, but they must be prefixed by "par...
          • you can use named parameters in user macros, but they must be prefixed by "param". for example:
          ## create an iframe element
          ##
          #if($paramsrc && $paramsrc.length()>0)
          #set($src=$!paramsrc )
          #else
          #if($param0 && $param0.length()>0)
          #set($src=$!param0)
          #else
          #set($src="")
          #end
          #end
          ##
          #if($paramwidth && $paramwidth.length()>0)
          #set($width=$!paramwidth)
          #else
          #if($param1 && $param1.length()>0)
          #set($width=$!param1)
          #else
          #set($width="800")
          #end
          #end
          ##
          #if($paramheight && $paramheight.length()>0)
          #set($height=$!paramheight )
          #else
          #if($param2 && $param2.length()>0)
          #set($height=$!param2)
          #else
          #set($height="500")
          #end
          #end
          ##
          #if($paramtext && $paramtext.length()>0)
          #set($text=$!paramtext)
          #else
          #set($text=$src)
          #end
          ##
          <div> <div>Remote Content: <a href="${src}">${text}</a></div> <div><iframe src="${src}" width="${width}" height="${height}" style="border:2px solid red;"></iframe></div> </div>
          

          usage:

          {iframe:src=http://www.google.ca|width=500px|height=300px}
          
          • works on our 2.5.7 install (and has worked since 2.10)
          • if you want to always use the scr/width/height parameters, and no warning text, you could just use this
            <iframe src="$!{paramsrc}" width="$!{paramwidth}" height="$!{paramheight}" style=""></iframe>
            
          • works on our 2.5.7 install (and has worked since 2.10)
  37. May 23, 2008

    Jessica Britton says:

    Is it possible to create a "run-once" user macro that generates wiki markup and ...

    Is it possible to create a "run-once" user macro that generates wiki markup and inserts it on the page as if the markup was natively written there?

    I'd like to be able to create a user macro to make it easy to generate some formatted links, but I'd also like those links to update if/when pages are moved or renamed later.

    Here's our user macro:

    
    {bgcolor:#e9f3dc}
    {section}
    {column:width=33%}
    {align:left}&nbsp;&nbsp;[*Previous*|$param0]
    {align}
    {column}
    {column:width=34%}
    {align:center}[*Index*|$param1]
    {align}
    {column}
    {column:width=33%}
    {align:right}[*Next*|$param2]&nbsp;&nbsp;
    {align}
    {column}
    {section}
    {bgcolor}
    
    

    Ideally I'd like to simply use it on a page like this:

    
    {navbar:Page 1 | TOC | Page 3}
    
    

    And end up with the actual wiki code on the page so the links are dynamically updated:

    {bgcolor:#e9f3dc}
    {section}
    {column:width=33%}
    {align:left}&nbsp;&nbsp;[*Previous*|Page 1]
    {align}
    {column}
    {column:width=34%}
    {align:center}[*Index*|TOC]
    {align}
    {column}
    {column:width=33%}
    {align:right}[*Next*|Page 3]&nbsp;&nbsp;
    {align}
    {column}
    {section}
    {bgcolor}
    
    1. May 27, 2008

      Tony Cheah Tong Nyee says:

      Hi Jessica, To my understanding, parameters ($param0....) feature available for...

      Hi Jessica,

      To my understanding, parameters ($param0....) feature available for the User Macros are static values. Having said that, any changes to the Page title would not reflect the parameters defined in the user Macros.
      Perhaps, you may be interested to look at the Navigation Plugin which provide a similar feature to the "User Macro" that you have created.
      If the above is not an option for you, you might need to create a macro plugin of your own that provides you this feature.

      Cheers,
      Tony

  38. Jun 18, 2008

    Jason Kabel says:

    How do you access the entire list of parameters as an array? How am I supposed t...

    How do you access the entire list of parameters as an array? How am I supposed to know how many parameters there are?

     I am building a macro that is basically a collection of other macros, namely to create a header that is both toc and children. I want to pass the parameters of my macro directly to the constituent toc macro. What is the best pattern for doing this? I would like users to use my macro with toc options exactly as they would use the basic toc macro.

    Thanks

    1. Jun 23, 2008

      Tony Cheah Tong Nyee says:

      Hi Jason, To my understanding, User Macros allows inputting standard parameters...

      Hi Jason,

      To my understanding, User Macros allows inputting standard parameters($param0-n) based on how it is defined in the macro's template. For any advance parameters to passed on to the macros, we encourage you to create a Macro Plugins of your own instead.
      Should you have further questions regarding customization, feel free to try our forums or the developer mailing lists. Users or developers who have experience in similar customization might share their idea with you.

      Cheers,
      Tony

    2. Jan 27

      Shawn Stepper says:

      Did you find an answer to this? I need to do the same thing.

      Did you find an answer to this? I need to do the same thing.

      1. May 06

        Shawn Stepper says:

        I ended up doing this, which works well for arbitrary number and order of parame...

        I ended up doing this, which works well for arbitrary number and order of parameters:

        #set ($argv = ["$param0","$param1","$param2","$param3","$param4","$param5","$param6","$param7","$param8","$param9","$param10","$param11","$param12","$param13","$param14","$param15","$param16","$param17","$param18","$param19","$param20"])
        
        #foreach ($myParam in $argv)
          #if ($myParam == "something")
            #set($something = true)
          #end
          #if ($myParam == "somethingelse")
            #set($somethingelse = true)
          #end
        #end
        

        I hope this helps!

  39. Jul 25, 2008

    Nicholas Whitehead says:

    I wrote this quickie user macro to hide and display large content in a confluenc...

    I wrote this quickie user macro to hide and display large content in a confluence page (like jiraissues macros). It starts out with the content hidden, but clicking the link toggles between display and hide.

     Use:

    • Macro Has a Body: true
    • Convert Body Wiki markup to HTML
    • Macro generates HTML Markup
     Usage:
    {hidedisplay:<id>}<body>{hidedisplay}
    

    The id is an arbitrary (but unique for the page) identier. The body is the content you wish to hide/display. This works fine with embedded macros.

    The Code:

    [<span onClick="var myDiv = document.getElementById('$param0'); if(myDiv.style.display=='none') { myDiv.style.display='block'; this.innerHTML='<i><u>Click to Hide</u></l>';} else {myDiv.style.display='none'; this.innerHTML='<i><u>Click to Display</u></l>';} "><i><u>Click to Display</u></l></span>]
    <div id="$param0" style="display:none">
    $body
    </div>
     
    


    1. Jul 29, 2008

      James Mortimer says:

      This seems very similar to Expand User Macro In the spirit of collaboration an...

      This seems very similar to Expand User Macro

      • In the spirit of collaboration and keeping things simple, would you work your macro into the pre-existing Expand User Macro?
      • Tim recently improved the expand user macro to auto-generate a unique id, so a user does not need to provide one.
  40. Aug 04, 2008

    Anonymous says:

    Hi, How can I have a People Directory button in a new dashboard? I found ...

    Hi,

    How can I have a People Directory button in a new dashboard?

    I found the create space button macro and it works, but i cannot find any macro for people directory button.

    thanks in advance.

    1. Aug 04, 2008

      Anonymous says:

      btw, I am using Confluence 2.7 thanks again!

      btw, I am using Confluence 2.7

      thanks again!

      1. Aug 04, 2008

        Azwandi Mohd Aris says:

        Hi there, I believe you are referring to a new space/page instead of dashboard....

        Hi there,

        I believe you are referring to a new space/page instead of dashboard. Anyway, I am afraid that there is no macro for creating people directory button available at this moment (similar to the create space button macro). However, you can try to create a user macro that will display the same icon for people directory. A simple example would be:

        <a href="http://PATH_TO_CONFLUENCE/peopledirectory.action">
        <img src="http://PATH_TO_CONFLUENCE/images/icons/people_directory_32.gif">
        </a>
        

        or in wiki markup:

        [!http://PATH_TO_CONFLUENCE/images/icons/people_directory_32.gif!|http://PATH_TO_CONFLUENCE/peopledirectory.action]
        
        

        Hope this helps.

        Cheers,
        Azwandi

        1. Aug 05, 2008

          Anonymous says:

          Hi Azwandi, Thanks, this would do but not when we have to move o...

          Hi Azwandi,

          Thanks, this would do but not when we have to move our new dashboard to another server.  We need something similar to create a space button macro, no hard coding of path so that in the future we're not going to have a broken link.  Any other way?

          1. Aug 12, 2008

            Azwandi Mohd Aris says:

            Hi there, A simple way that I can think of is by removing the base URL, as in: ...

            Hi there,

            A simple way that I can think of is by removing the base URL, as in:

            <a href="/peopledirectory.action">
            <img src="/images/icons/people_directory_32.gif">
            </a>
            

            Cheers,
            Azwandi

  41. Aug 14, 2008

    Mark Sheppard says:

    I want to get a list of pages in a macro and according to this I should be using...

    I want to get a list of pages in a macro and according to this I should be using a SpaceManager method. However I can't work out to get the SpaceManager object - as far as I can tell there's no way of getting it from $space, $generalUtil, $action or $page.

    For now I'm using the deprecated method, but would prefer not to. I've noticed a couple of other things like this too where I can't access various managers and have had to use deprecated methods instead.

    Is there any way to get to the SpaceManager object from user macros?

    1. Mar 12

      Paul-Dieter Klumpp says:

      I know your question is quite old.. still, here's an answer: #set ($spaceMana...

      I know your question is quite old.. still, here's an answer:

      #set ($spaceManager = $space.setSpaceManager())
      #set ($countPages = $spaceManager.findPageTotal($space))
      $countPages
      
  42. Aug 14, 2008

    Mark Sheppard says:

    Is there any way to create a new object in a macro? The particular case I wante...

    Is there any way to create a new object in a macro?

    The particular case I wanted was to get a java.util.Date object and I managed to work round it be using this:

    #set($end = $generalUtil.getBuildDate().clone())
    #set($ret = $end.setYear($year))
    #set($ret = $end.setMonth($month))
    #set($ret = $end.setDate($day))
    

    However it'd be useful to know how to create arbitrary objects for other things in future.

    1. Aug 18, 2008

      Tony Cheah Tong Nyee says:

      Hi, As far as I know, user cannot initiate any Java object in Confluence. Howev...

      Hi,

      As far as I know, user cannot initiate any Java object in Confluence. However, Confluence allows you to access some of the predefined Confluence objects:

      You can get java.util.Date object, using the following method:

      $content.getCurrentDate()
      

      Regards,
      Tony

  43. Aug 18, 2008

    Peter Smith says:

    I think the '$page' object is not available.

    I think the '$page' object is not available.

    1. Sep 01, 2008

      Tony Cheah Tong Nyee says:

      Hi Peter, Indeed, the '$page' object is not available for user macro. Alternati...

      Hi Peter,

      Indeed, the '$page' object is not available for user macro. Alternatively, one may use the $content object instead which is a supported object when creating a User Macro.

      Cheers,
      Tony

      1. Oct 16, 2008

        Anonymous says:

        I was on the same boat as Peter looking for the page object to use in an user ma...

        I was on the same boat as Peter looking for the page object to use in an user macro.

        Thank you, Tony, for your feedback 

        -nga