Macro that lists all pages for the specified space with their parameters
Asked by Vladimir Vakhlov:

Greetings,

I am trying to list all pages in the space/page and put them into the table with their current version and last comment.  

I've google a bit and figured out it shoud be something like this... However the array of listpages seems to be empty.  

What am I doing wrong?  

```
## @param Page:title=Page|option-showTitleInPlaceholder=true|type=confluence-content|desc=Target page

#if ($paramPage.contains(':'))
#set ( $strArray = [] )
#foreach($str in $paramPage.split(':'))
#set($dummy = $strArray.add($str)) ## Assign returnval to avoid printing 'true'.
#end
#set($spacekey = $strArray.get(0).trim())
#set($pagetitle = $strArray.get(1).trim())
#else
#set($spacekey = $content.getSpaceKey()) ## Current spacekey
#set($pagetitle = $paramPage.trim())
#end


#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 ($listpages=$pageManager.getPages($spacekey, $pagetitle))


<table>
<tr>
<th>Page Name</th>
<th>Current Version</th>
<th>Change Comment</th>
</tr>
#foreach($listpage in $listpages)
<tr>
<td>X $listpage.getTitle()</td>
<td>Y $listpage.version</td>
<td>Z $listpage.getVersionComment</td>
</tr>
#end
</table>
```


Answers:
author: Vladimir Vakhlov
body: Here you go, Vlad! :)  

```

## @param SpaceKey:title=Space Key|type=string
#set ( $spaceToDisplay = "" )
#set ( $spaceToDisplay = $spaceManager.getSpace($paramSpaceKey) )

#if ( !$paramSpaceKey )
#set ( $spaceToDisplay = $space )
#end

#if ( $spaceToDisplay == "" )
<p> Space with key "$paramSpaceKey" not found. </p>
#else
#set ( $topLevelPages = $pageManager.getTopLevelPages($spaceToDisplay) )

<table style="padding: 0px">
<tr>
<th>Page</th>
<th>Last modified</th>
<th>Author</th>
</tr>
#foreach ( $topLevelPage in $topLevelPages )
<tr >
<td style="font-variant: small-caps; padding: 2px 10px; border-color: #E9E9E9;"> <a href="${req.contextPath}$topLevelPage.urlPath"> $topLevelPage.title </a> </td>
<td style="padding: 2px 10px; border-color: #E9E9E9;">$action.dateFormatter.formatDateTime($topLevelPage.getLastModificationDate())</td>
<td style="padding: 2px 10px; border-color: #E9E9E9;"> $topLevelPage.getLastModifier().getFullName()</td>
</tr>
#parseChildren($topLevelPage)
#end

</table>
#end

#macro(parseChildren $pageToParse)
#set ( $pageChildren = $pageToParse.getChildren() )
#if ( $pageChildren != "[]" )
#foreach($childPage in $pageChildren)
<tr>
<td style="font-variant: small-caps; padding: 2px 10px; border-color: #E9E9E9;"><a href="${req.contextPath}$childPage.urlPath" style="font-variant: small-caps"> -> $childPage.title </a></td>
<td style="padding: 2px 10px; border-color: #E9E9E9;"> $action.dateFormatter.formatDateTime($childPage.getLastModificationDate())</td>
<td style="padding: 2px 10px; border-color: #E9E9E9;"> $childPage.getLastModifier().getFullName()</td>
</tr>
#parseChildren($childPage)
#end
#end
#end
```


Tags: confluence-server

macro

page

server