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

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

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

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

"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.

I would like this too!

-Emily

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?

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

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.

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).

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!

+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.

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?

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,

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.

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? 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Tuesday in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

396 views 17 9
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you