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

Possible to Call User Macro inside another User Macro?

Phillip Ponzer [Cprime]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 21, 2011

Is it possible to call a user macro inside of another user macro?

If so, how?

If not, then is it possible to create functions inside a user macro to be called throughout the user macro?

If so, how?

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
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.
November 21, 2011

Add this to your user macro to get the gist of things

#macro (listStuff $name, $stuff)
    <h2>$name</h2>
    <ul>
        #foreach ($thing in $stuff)
            <li>$thing</li>
        #end
    </ul>
#end

#set( $stuff = ["Confluence","JIRA","Bamboo","Sourcetree"] )
#listStuff("Atlassian Software", $stuff)

...it passes some stuff into a velocity macro and prints an unordered list.

Phillip Ponzer [Cprime]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 21, 2011

Thanks! That's exactly what I was looking for. :)

4 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.
November 21, 2011

Try this:

The cheese macro:
$helper.renderConfluenceMacro("{cheese}")

...or similar

Phillip Ponzer [Cprime]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 21, 2011

Excellent! That works great!

I also found this (via http://confluence.atlassian.com/display/DOC/Writing+User+Macros):

<ac:macro ac:name="someOtherMacro" />

But am I constrained to using user macro's? Is there the capability to create/use functions within a user macro?

Phillip Ponzer [Cprime]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 21, 2011

I found this answer to be helpful too: https://answers.atlassian.com/questions/11054/confluence-4-0-user-macro-wiki-markup-template-must-now-be-html/11062

<ac:macro ac:name="toc">
    <ac:parameter ac:name="style">circle</ac:parameter>
</ac:macro>
Stefan Baader June 28, 2019

With the current CONF version 6.9

$action.getHelper().renderConfluenceMacro("{some-user-macro}")

0 votes
Matthias Born December 15, 2011

We have a "subject" macro that creates the "excerpt" and a optional "toc".

To implement for C4 I tried this:

## @param toc:title=Inhaltsverzeichnis generieren|type=boolean|desc=Wenn aktiviert, wird ein Inhaltsverzeichnis erzeugt, das nicht mit gedruckt wird.|required=false|default=false

<div style="border-width: 1px;" class="panel">
<div class="panelContent">
<ac:macro ac:name="excerpt">
	<ac:parameter ac:name="atlassian-macro-output-type">BLOCK</ac:parameter>
	<ac:rich-text-body>$body</ac:rich-text-body>
</ac:macro>
#if ($paramtoc)
	<ac:macro ac:name="toc">
		<ac:parameter ac:name="printable">false</ac:parameter>
	</ac:macro>
#end
</div>
</div>


Unfortunately the <ac...> content is ignored (not rendered) completely.

Any ideas?

Regards!
Matze

Sven
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 22, 2011

guess you should use:

$action.getHelper().renderConfluenceMacro("{info:title=Hinweise}Hint{info}")

This works very well for me in all situations where I have to "upgrade" usermacros to 4.x...

Sometimes I have to use a combination of "Insert Wiki-Markup" and a usermacro in the middle (e.g. for loops)

Not very comfortable to have to find out the "good old wiki markup syntax" for all the macros (to be used in user macros), but the confluence 3.5.x-Online-Help is very useful for this...

Or is there another way?

Just to give an example:

usermacro "space-access":

## @noparams
#set ($prevname = "")
#foreach ($perm in $space.getPermissions())
  #if ($perm.isUserPermission())
    #if ($prevname != $perm.getUserName())
      #set ($prevname = $perm.getUserName())
       $action.getHelper().renderConfluenceMacro("{user-reporter:user=$perm.getUserName()}")
    #end
  #else
    #if ($prevname != $perm.getGroup())
      #set ($prevname = $perm.getGroup())
     $action.getHelper().renderConfluenceMacro("{user-reporter:group=$perm.getGroup()}")
    #end
  #end
#end

...must be used inside this in a wiki-page (included by "Insert Wiki-Markup")

{report-block}
{combining-reporter:unique=true}
{space-access}
{combining-reporter}
{report-body}
{report-info:user:full name|link=true}
{report-body}
{report-block}

Not very comfortable, but at least it works!

TAGS
AUG Leaders

Atlassian Community Events