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

Confluence - apply a macro to all children pages of a space

Daniel Tran November 30, 2011

Hi,

I'm new to the forums and was hoping I could get some help, somewhat new to developing in confluence so bear with me.

I was wondering if there was a plugin or a method to apply a macro to all children pages of a specific space. For example, my space 'test' has 100 children pages/news and i'd like to automatically add the macro to all the pages (by adding {testmacro} to the wiki-markup of each page)

I was told to create my own confluence plugin but I ran into several problems with maven and was thinking maybe I'd look to see if there was already a method to do this.

Thanks in advanced,

Daniel

7 answers

1 vote
Christoph Meier November 10, 2016

Unfortunately this doesn't work, if the macro is part of a plugin (written as a Java class which implements com.atlassian.confluence.macro.Macro).

Or i failed to reference it properly.

Neither
$helper.renderConfluenceMacro("{mgnl-space-jump}")
nor
{mgnl-space-jump} 
worked, when i was adding the snippet into the header of the space.

mgnl-space-jump is both the name and the key of the macro. The macro is registered in the atlassian-plugin.xml like this:

<xhtml-macro name="mgnl-space-jump" class="info.magnolia.sys.confluence.plugin.mgnltools.macro.SpaceJump" key="mgnl-space-jump">
<parameters/>
</xhtml-macro>

Can anyone help, please? 

1 vote
Matthew J. Horn
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.
June 3, 2012

If you have permissions, you can edit the space's Page Layout and add the macro in the markup by using the $helper.renderConfluenceMacro() method; for example:

$helper.renderConfluenceMacro("{testmacro}")

hth,

matt

Vishali
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.
January 9, 2013

Matthew,

I want {Children Display} in all the pages and would like to use this in the Page Layout - $helper.renderConfluenceMacro("{Children Display}"). Where exactly should I place this?

Thanks

Matthew J. Horn
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.
January 9, 2013

"edit the space's Page Layout and add the macro in the markup":

Edit the space using a URL similar to:

http://yoursite.com/spaces/listdecorators.action?key=spacename

Selec the Space Admin tab.

Under Content Layouts, click Create Custom next to Page Layout. If you've already customized the page layout, click the Edit button.

In that decorator, add it where you want it to appear. Takes a little playing around before you might understand all the little pieces in there, but the HTML fragments should be sufficient to help you figure it out.

0 votes
Vishali
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.
January 9, 2013

Daniel,

It worked for me. But I get the page title and the navigation menu at the bottom of the page (wherein I wanted them to appear at the top of the page).

Thanks,

Daniel Borcherding
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.
January 10, 2013

Which of the sections did you place the markup? Navigation, Header or Footer?

I think you may have put it into the header of the page. The header is rendered above the page title and edit dialog box on the page. If you want it to render of the body of the page you are going to have to go through on a page by page basis and insert this macro. There is no way to my knowledge to globablly apply a macro to all pages other than what Matt suggested.

0 votes
Daniel Borcherding
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.
January 9, 2013

Hello Daniel,

Matt's solution to this problem is an excellent one. Modifying the layout of a space is a great way of injecting a macro into all pages in a space.

If you are using a Theme like the Documention Theme you will not be able to modify the layout of a space. Your option here would be to visit the Space Admin > Themes > Configure Theme. You can then place the {children} macro in the Navigation, Header or Footer portion of the teme.

Please let us know if that will work for you.

Vishali
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.
January 9, 2013

Daniel,

It worked for me. But I get the page title and the navigation menu at the bottom of the page (wherein I wanted them to appear at the top of the page).

Matthew J. Horn
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.
January 9, 2013

Like I said, spend some time getting to know the decorators. I did this when I first started mucking around: I edited the global and page layouts and inserted a code (numbers and/or letters) every couple of lines. Then I requested the pages in Confluence, and cross checked where the codes showed up with what macro or Velocity syntax or HTML was in the decorator. Then I went in and commented the files and removed the numbers so I'd know where to start when I wanted to make changes. (I was working on a staging site, so I didn't have to worry about users seeing my "numbering".)

Not the smoothest approach, but it really helped me understand the structure of these files. It's a shame they aren't better documented to begin with!

Daniel Borcherding
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.
January 10, 2013

+1 to improving the documentation on velocity syntax. If you notice any pages that need some attention please email dborcherding at atlassian.com a link. I will do what I can to help with the docs.

Joe Reyna March 14, 2013

It looks like I'll have to switch themes, then edit the original theme, then switch it back. Is this safe to do without causing unwanted changes to the pages within the space?

0 votes
Matthew J. Horn
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.
June 3, 2012

If you have permissions, you can edit the space's Page Layout and add the macro in the markup by using the $helper.renderConfluenceMacro() method; for example:

$helper.renderConfluenceMacro("{testmacro}")

hth,

matt

0 votes
mike.howells June 3, 2012

Maybe there's an easier way to do what you're trying to do. What outcome do you want from this from a user's point of view?

0 votes
Emily Johnson January 18, 2012

I would like this too!

-Emily

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events