Display list of pages and their current versions
Asked by danoz:

Hi there,

I'm wondering if anybody could please help me with the following...

I am using Confluence Cloud. I would like to create a confluence page, think of it like an index or contents page, that lists a number of other pages contained within the space along with the current version and change log for each page listed.

For example...

**Welcome to my Index/Contents page**

|   *Page Name*    | *Current Version* |  *Change Comment*  |
|------------------|-------------------|--------------------|
| Example page 1   | v. 1              | Initial version    |
| Some other page  | v.3               | Made a few changes |
| Yet another page | v. 2              | Minor spelling fix |

I would like the *Current Version* and *Change Comment* values to be referenced from the actual pages themselves. That way they would always stay current/up-to-date automatically and wouldn't require me to update them manually.

Does anyone know if this is possible?

Thanks in advance for your time considering this question.

Regards,  
Dan


Answers:
author: Franz Limbacher
body: Hi Dan,

Of course its possible!

You have two possabilites:

* You can write an User Macro or
* you can write a Plugin with an Macro Modul

Either ways, the functionality is pretty the same.

Via the contentAcessor you get the pageManager.  
Via pageManager you get the Page by name (for example a parameter)  
You can also use getPages or getPagesStartingWith   
For each page you can get the children of a page.  

For a User Macro it could look like this (I didn't test it):

```
## Set the Parameters ?# (...)## Specify the page, this macro is based on#set($key="SPACE")#set($name="Page")## Specify the parameters for that page## (...)## Get PageManager object instance#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')) ## Get the Pages#set($pages=$pageManager.getPagesStartingWith($key,$name))## Render the page with the parameters above&lt;table&gt;  &lt;tr&gt;    &lt;th&gt;Page Name&lt;/th&gt;    &lt;th&gt;Current Version&lt;/th&gt;     &lt;th&gt;Change Comment&lt;/th&gt;  &lt;/tr&gt;?#foreach($page in $pages)  &lt;tr&gt;    &lt;td&gt;$page.getTitle()&lt;/td&gt;    &lt;td&gt;$page.getLatestVersion()&lt;/td&gt;     &lt;td&gt;$page.getVersionComment&lt;/td&gt;  &lt;/tr&gt;#end&lt;/table&gt;
```

For Documentation of the classes and functions read this:

<https://docs.atlassian.com/atlassian-confluence/latest/com/atlassian/confluence/pages/PageManager.html>  
<https://docs.atlassian.com/atlassian-confluence/latest/com/atlassian/confluence/pages/Page.html>

If you need help for writing User Macros: <https://confluence.atlassian.com/doc/writing-user-macros-4485.html>

[](https://confluence.atlassian.com/doc/writing-user-macros-4485.html)If you need help for writing Plugin Macros: <https://developer.atlassian.com/confdev/tutorials/macro-tutorials-for-confluence/creating-a-new-confluence-macro>

I hope this helps you.

Kind Regards Franz

comments: author: Lionel Seaw
body: hi... do you happen to have a working version of this macro? i need to display a table of all child pages and their versions


Tags: cloud

confluence-cloud