Include children macros

Jamil Rahimov
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 31, 2020

Currently I'm using Include children macros. (This macros indicates all children of another page on current page)

//---------------------------------------------------------------------------------------------------

For example as you can see there is other articles page and it has children:
Other articles.PNG

//------------------------------------------------------------------------------------------------

I showed children page of Other articles on another page

test.PNG
But there is latency problem when I want open page it opens very late.
What can I do for resolve this problem?

User macros code:

## Macro Name: include_children
## Visibility:
## Macro Title: Include Children
## Description: This will include the content from from the child pages onto the parent page that this macro is placed on.
## Categories: Confluence content
## Icon URL:
## Documentation URL: https://bitbucket.org/fredclown/confluence-user-macros
## Macro Body Processing: No macro body

##############################
## Template: ##
##############################
## Developed By: Davin Studer
## Date Created: 12/4/2014
## Updated by: Milo Grika
## Added: show/hide title, link/unlink title.
## Updated by: Gregor Mirai
## Date updated: 26/1/2016
## Added: page separator, PDF split page marker options.
## Updated by: Davin Studer
## Date updated: 4/13/2018
## Added: Include Descendants checkbox
## Updated by: Davin Studer
## Date updated: 12/3/2018
## Added: Added an option to specify the parent page.

## @param ShowTitle:title=Show Title|type=boolean|desc=Deselect to remove the title of the child page.|default=true
## @param LinkTitle:title=Link Title|type=boolean|desc=Select to turn the titles of the child pages into links to those pages (Show Title must be selected).|default=false
## @param IncludeDescendants:title=Include Descendants|type=boolean|desc=Select to include descendants.|default=false
## @param PageSeparator:title=Page Separator|type=boolean|desc=Separate pages with horizontal ruler.|default=false
## @param SplitPages:title=Split Pages|type=boolean|desc=Split pages marker for PDF export will be inserted.|default=false
## @param Collapsible:title=Collapsible|type=boolean|desc=Should the included pages be collapsible?|default=false
## @param FilterLabel:title=Filter on Page Label|type=string|desc=Include only subpages with the specified label.
## @param Page:title=Page title|type=confluence-content|required=false|desc=If not specified, the current page is used.
## @param Order:title=Order|type=enum|enumValues=Nav Order,Reverse Nav Order,Alphabetical,Reverse Alphabetical,Create Date,Reverse Create Date|default=nav order|desc=In what order should the child pages be displayed? Nav Order refers to the order of the child pages in the page tree. Reverse Nav Order simply reverses that.

#set( $containerManagerClass=$content.class.forName('com.atlassian.spring.container.ContainerManager') )
#set( $getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null) )
#set( $containerManager=$getInstanceMethod.invoke(null,null) )
#set( $containerContext=$containerManager.containerContext )
#set( $pageManager=$containerContext.getComponent('pageManager') )

#if( $paramPage && $paramPage != "" )
##########################
## Find the page ##
##########################
#set( $parts = $paramPage.split(":") )
#set( $i = 0 )
#set ( $len = 0 )
#set( $key = "" )
#set( $name = "" )

##Having trouble finding out the length/size of $parts ... brute force it
#foreach ( $part in $parts )
#set ( $len = $len + 1 )
#end

#if ( $len == 1 )
#set ( $key = $content.spaceKey )
#set ( $name = $paramPage )
#else
#foreach ( $part in $parts )
#if ( $i == 0 )
#set ( $key = $part )
#set ( $i = $i + 1 )
#else
#set ( $name = $part )
#end
#end
#end

#set ( $tempcontent = "" )
#if ( $pageManager )
#set ( $tempcontent = $pageManager.getPage($key, $name) )
#end
#if ( $tempcontent && $tempcontent != "" )
#set ( $content = $tempcontent )
#else
The page "$paramPage" was not found in this space.
#set ( $content = "" )
#end
#end

#set( $data = "" )
#childPages ( $content.id )

#macro ( childPages $pageid )
## Find the array of (sorted) child pages.
#if( $paramOrder == "Nav Order" || $paramOrder == "Reverse Nav Order" )
#set( $children = $pageManager.getPage($pageid).getSortedChildren() )
#elseif( $paramOrder == "Alphabetical" || $paramOrder == "Reverse Alphabetical" )
#set( $array = $pageManager.getPage($pageid).getChildren() )
###############################################################
## Could not find a method to get them in Alphabetical order ##
## Must sort them myself ... Bubble sort ##
###############################################################
#set( $size = $array.size() )
#foreach( $junk in $array )
#set( $count = -1 )
#foreach( $line in $array )
#set( $count = $count + 1 )
#if( $velocityCount < $size )
#if( $line.getTitle().compareToIgnoreCase($array.get($velocityCount).getTitle()) > 0 )
#set( $tmp = $array.get($velocityCount) )
#set( $junk = $array.set($velocityCount, $line) )
#set( $junk = $array.set($count, $tmp) )
#end
#end
#end
#end
#set( $children = $array )
#elseif( $paramOrder == "Create Date" || $paramOrder == "Reverse Create Date" )
#set( $children = $pageManager.getPage($pageid).getChildren() )
#end

## Prepare children data.
#foreach( $child in $children )
## Create the map of labels for the page.
#set( $labelsMap = {} )
#foreach( $label in $child.getLabels() )
#set( $dummy = $labelsMap.put($label.toString(), 1) )
#end

## Include all pages (when no filter label is specified) or pages with a specific label.
#if( !$paramFilterLabel || $paramFilterLabel && $labelsMap.containsKey($paramFilterLabel) )
#set( $include = "" )
#if ( $paramCollapsible == true )
#set( $include = $include + '<ac:structured-macro ac:name="expand">' )
#set( $include = $include + '<ac:parameter ac:name="title">' + $child.getTitle() + '</ac:parameter>' )
#set( $include = $include + '<ac:rich-text-body>' )
#set( $include = $include + '<p>' )
#end
#set( $include = $include + '<div class="included-child-page">' )

## Show title and links.
#if( $paramShowTitle == true )
#if( $paramLinkTitle == true )
#set( $include = $include + '<h1 class="included-child-page-title"><a href="' + $child.getUrlPath() + '">' + $child.getTitle() + '</a></h1>' )
#else
#set( $include = $include + '<h1 class="included-child-page-title">' + $child.getTitle() + '</h1>' )
#end
#end

## Include sub page.
#set( $include = $include + '<div class="included-child-page-body">' )
#set( $include = $include + '<ac:structured-macro ac:name="include">' )
#set( $include = $include + '<ac:parameter ac:name="">' )
#set( $include = $include + '<ac:link>' )
#set( $include = $include + '<ri:page ri:content-title="' + $child.getTitle() + '" ri:space-key="' + $content.spaceKey + '"/>' )
#set( $include = $include + '</ac:link>' )
#set( $include = $include + '</ac:parameter>' )
#set( $include = $include + '</ac:structured-macro>' )
#set( $include = $include + '</div>' )
#set( $include = $include + '</div>' )

#if ( $paramCollapsible == true )
#set( $include = $include + '</p>' )
#set( $include = $include + '</ac:rich-text-body>' )
#set( $include = $include + '</ac:structured-macro>' )
#end

## Define sorting order.
#set( $inOrder = false )
#if( $paramOrder == "Nav Order" || $paramOrder == "Alphabetical" || $paramOrder == "Create Date" )
#set( $inOrder = true )
#end

## Include page separator or include page split marker used for PDF exports.
#if( $paramPageSeparator == true )
#set( $include = $include + '<hr/><br/>' )
#end
#if( $paramSplitPages == true )
#set( $include = $include + '<div style="page-break-before:always;"></div>' )
#end

## Add page content in order or in reverse order.
#if( $inOrder == true )
#set( $data = $data + $include )
#else
#set( $data = $include + $data)
#end
#end

#if($paramIncludeDescendants == true)
#childPages( $child.id )
#end
#end
#end

$data

<style type="text/css">
.included-child-page {
margin-bottom: 30px;
overflow: hidden;
}
</style>

 

2 answers

0 votes
nightwww
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 16, 2023

Hi guys, you need  add the below to the setenv.sh:

CATALINA_OPTS="Dmacro.required.velocity.context.keys=pageManager,spaceManager,attachmentManager,permissionHelper,userAccessor,i8n,dateFormatter,res,settingsManager,htmlUtil,generalUtil,bootstrap,containerContext,action,req,content ${CATALINA_OPTS}"

 

its help for me.

Best regards Aleksey.

Martin Hudak
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 16, 2023

Hi Aleksey, many THANKS it DID help !!! (one little mistake "-" char is missing before Dmacro, -Dmacro etc. is correct)

Here is some info about the reason: https://developer.atlassian.com/server/confluence/confluence-objects-accessible-from-velocity/

In Confluence 7.13 LTS (7.13.15), Confluence 7.19 LTS (7.19.7), Confluence 8.2 (8.2.0) and later versions, the user macro Velocity context is set to include only the generalUtil and bootstrap variables. To change or add more variables, you will need to configure the system property macro.required.velocity.context.keys. See configuring system properties to learn how.

0 votes
Shannon S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 10, 2020

Hello Jamil,

Thank you for raising this with us.

How long would you say it takes the Children Display Macro to load? How many children are there? If there are too many, it can cause performance issues when loading the descendants. If you try reducing the number of children pages that load, does the load time reduce? 

Lastly, I see you shared a user macro code, can you let me know what that is for and what you're trying to do with that?

Regards,

Shannon

Jamil Rahimov
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.
February 11, 2020

@Shannon S 
My task is showing all children in one page to make it easier for users.
They want see all documents in one page rather than separately.
Yes depending on count of pages it reduces the performance.
Number of children can be different.
I need optimize system or this macros for realizing better performance regardless of number of pages.(If it is possible)

Shannon S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 12, 2020

Hi Jamil,

My apologies; I hadn't seen your response to what the code was that you included, but it just occurred to me that you are not having an issue with the Confluence Children Display Macro, but with a User Macro called Include Children. I'm not familiar with that User Macro, but it looks like it originates from this Bitbucket repository.

I would recommend trying to use the built-in Children Display macro instead to see if that helps you accomplish the same thing, otherwise you might need to see if you can get in touch with the original creator of that User Macro.

Regards,

Shannon

Like Jamil Rahimov likes this
nightwww
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 3, 2023

Hello, after updating to 8.3.0, the macros  stopped working.

Like Martin Hudak likes this
Martin Hudak
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 16, 2023

The same here, after update to 8.3.0 it does not work anymore :( .

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events