How to display a list of sub-pages AND their content on parent page?
I know you can put 'exceprt' on every page and display excerpts on parent page. But:
Any solution?
@Davin Studer's macro has been updated a little bit (code on github) with some new options (page separator, PDF page splitting and filtering on labels).
You could use the children display macro to display all child pages and some fragment of them (excerpts).
If you want to show the whole content of the page, you will have to use the include page macro. Unfortunately, you will have to add an instance of the macro for every page you want to include and there is not a quick way to insert all child pages.
This also sound like something that could be done creating your own user macro. Unfortunately this may be complex.
Another option would be to use the Navitabs add-on. It has a macro to create a tab for each child page and put the contents of each child page into the respective tab.
@Alejandro Conde Carrillo
'Children display' macro does not display entire excerpt. This will not do.
Using 'include page' can't be automated (unless you know something I don't know)
@Davin Studer
'Nacitabs' add-on will display tabs, you must click on tam to see what is there. This is not the solution
What about a user macro like this?
## Developed by: Davin Studer ## Date created: 12/4/2014 ## @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 Order:title=Order|type=enum|enumValues=Nav Order,Reverse Nav order,Alphabetical,Reverse Alphabetical,Create Date,Reverse Create Date|default=nav order|desc=What order should the child pages be displayed? Nav Order refers to the order of the child pages in the nav 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') ) #set( $data = "" ) #if( $paramOrder == "Nav Order" || $paramOrder == "Reverse Nav order") #set( $children = $pageManager.getPage($content.id).getSortedChildren() ) #elseif( $paramOrder == "Alphabetical" || $paramOrder == "Reverse Alphabetical") #set( $array = $pageManager.getPage($content.id).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($content.id).getChildren() ) #end #foreach( $child in $children ) #set( $include = "" ) #set( $include = $include + '<div class="included-child-page">') #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 #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( $paramOrder == "Nav Order" || $paramOrder == "Alphabetical" || $paramOrder == "Create Date" ) #set( $data = $data + $include ) #else #set( $data = $include + $data) #end #end $data <style type="text/css"> .included-child-page {margin-bottom: 30px;} </style>
Hi @Davin Studer
This is looking awesome. Will you be so kind and extent this with two simple (I hope so) options?
This would be exactly what we need
I managed to convert 'page title' into 'link' (line number 11):
## Developed by: Davin Studer ## Date created: 12/4/2014 ## @noparams #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') ) #foreach($child in $pageManager.getPage($content.id).getSortedChildren()) <h1><a href=$child.getUrlPath()>$child.getTitle()</a></h1> <p> <ac:structured-macro ac:name="include"> <ac:parameter ac:name=""> <ac:link> <ri:page ri:content-title="$child.getTitle()" ri:space-key="$content.spaceKey"/> </ac:link> </ac:parameter> </ac:structured-macro> </p> #end
But sorting is still mystery for me. Can anyone help?
I'm trying to make the page titles and linkability optional, but my limited programming skills are obviously holding me back.
I've created the parameters:
## @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
Which seems to function.
And the conditionals:
#if ( $paramShowTitle && $paramLinkTitle ) <h1><a href=$child.getUrlPath()>$child.getTitle()</a></h1> #elseif ( $paramShowTitle && !$paramLinkTitle ) <h1>$child.getTitle()</h1> #end
But it shows linked titles no matter which, if any, of the checkboxes are selected. (Removing the conditional altogether makes the titles not show, which satisfied my initial need, but options are good.)
Where did I go wrong?
I finally decided to tackle sorting on this. It's been bugging me for a while, but I just never had the time to get to it. I have edited my answer above to include sorting. It also includes the options to show/hide the title and link/unlink the title added by @Milo Grika. I also threw in some css classes (included-child-page, included-child-page-title, and included-child-page-body) so that it can be styled. included-child-page wraps each included child page. included-child-page-title and included-child-page-body are each child page's title and body.
I'm getting an error: Error rendering macro 'includechildren' : Error occurred rendering template content Though you totally showed me how to get the simple hide/show/link title thing working! Thanks for the lesson.
Hmmm. I've tried it on 5.5.6 and 5.8.6 and it works fine for me on both. I even tried copying and pasting from this post into a new user macro and it works for me. Sure it copied correctly?
I like what you have added.
I especially like the page break on PDF export. My only suggestion is that if the page separator is employed, it does not appear in the PDF if PDF page splitting is used.
Tnx for the idea Milo - the new version pushed to the github has your suggested change
Hi,
I am looking for the same. I want to display all child pages with tree structure using user macro, is this possible?
it should like
image2016-9-23 13:9:9.png
Regards,
Siddheshwar
If you just want a tree structure like your screenshot then use the pagetree macro and set the root page to @self.
I want to achieve this by using user macro because i need to change look and feel for the same
Can we change UI of pagetree macro something like
image2016-9-23 18:41:31.png
Ok. How about something like this? It will give you a "Collapsible" parameter in the macro setup that will surround the included pages with an expand macro if checked.
## 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.## @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 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 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') )## Find the array of (sorted) child pages.#set( $data = "" )#if( $paramOrder == "Nav Order" || $paramOrder == "Reverse Nav Order" ) #set( $children = $pageManager.getPage($content.id).getSortedChildren() )#elseif( $paramOrder == "Alphabetical" || $paramOrder == "Reverse Alphabetical" ) #set( $array = $pageManager.getPage($content.id).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($content.id).getChildren() )#end## Prepare children data. #set( $count = -1 )#set( $skipped = 0 )#set( $size = $children.size() )#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 && !$labelsMap.containsKey($paramFilterLabel) ) #set( $skipped = $skipped + 1) #else #set( $count = $count + 1 ) #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 ## Find out, whether we are in between pages or not. #set( $betweenPages = false ) #if( $inOrder == true && $count < $size - $skipped - 1 ) #set( $betweenPages = true ) #elseif( $inOrder == false && $count > 0 && $count < $size - $skipped ) #set( $betweenPages = true ) #end ## Include page separator or include page split marker used for PDF exports. #if( $betweenPages == true ) #if( $paramPageSeparator == true ) #set( $include = $include + '<hr/><br/>' ) #end #if( $paramSplitPages == true ) #set( $include = $include + '<div style="page-break-before:always;"></div>' ) #end #end ## Add page content in order or in reverse order. #if( $inOrder == true ) #set( $data = $data + $include ) #else #set( $data = $include + $data) #end #end#end$data<style type="text/css"> .included-child-page { margin-bottom: 30px; overflow: hidden; }</style>
It looks like you're new here. Sign in or register to get started.