Scriptrunner for Confluence - Subpages

Hello all,

I am quite excited about the Scriptrunner for Confluence. Does anyone of you know if it is also possible to insert a macro on a parent page which displays all the content of the subpages?

Thanks in advance!

3 answers

1 accepted

0 votes
Answer accepted
Mirek Community Champion May 31, 2016

You can always try to write your own user macro - It mostly depends how you want to show the content but it should be possible and quite easy to do if you will use in your macro build in include macros or any other useful like expand etc.

Hi - good question. A script macro for this is pretty straightforward. The config might look like:

image2016-5-31 14:58:12.png

No parameters are necessary.

The code is:

import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.xhtml.api.MacroDefinition
import com.atlassian.confluence.xhtml.api.XhtmlContent
import com.atlassian.renderer.v2.RenderUtils
import com.atlassian.sal.api.component.ComponentLocator

def xhtmlContent = ComponentLocator.getComponent(XhtmlContent)

def entity = context.getEntity()
if (entity instanceof Page) {
    def concat = (entity as Page).children.collect { child ->
        "<h2>${child.title}</h2>" +
            xhtmlContent.convertMacroDefinitionToStorage(new MacroDefinition("include", null, null, [
                "0"       : "${context.spaceKey}:${child.title}".toString(),
            ]), context)
    return xhtmlContent.convertStorageToView(concat, context)
else {
    RenderUtils.blockError("Error", "Should only be used on pages, not comments, blog posts, etc")

Seems to work for me. The secret is to write out a bunch of include macros, one for each child page. It also adds the page title as an h2.

This avoids having to deal with permissions errors, relative links and attachments, and so on.

It is kind of easy to do it with user macros, but it's also easy to cock stuff up. For instance, if you don't handle permissions properly, a user who does not have view permissions to some child page could access the content by adding a bad implementation of "include-children" to the root page.



Hi Dieter,

Yes, it is possible to include specific versions of pages using one of the bundled ScriptRunner for Confluence Bundled Macros called Include Version. You could certainly start with that.

If you have many instances of the "include page" macro you can also convert you pages to use the new macro.

We've also bundled an Includes Report macro so you can see what versions are included in your parent page and update them all if you wish.



Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 12, 2019 in Confluence

Confluence Admin Certification now $150 for Community Members

More and more people are building their careers with Atlassian, and we want you to be at the front of this wave! Important Dates Start the Certification Prep Course by 2 April 2019 Take your e...

1,544 views 4 13
Read article

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