This User Macro is very useful:

  • You can count pages in spaces
  • You can obtain the last modified date (and the modifier author if you want)
  • You can show a list of spaces with links to quick access
  • You can “clean” or “archive” old spaces

Installation instructions: (see picture)

Captura de pantalla 2019-05-03 a las 18.49.31.png

 

The Template of code (the source):

<pre>

## Macro title: Page counter
## Macro has a body: Y or N (N)
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: Cedric DEVAUX
## Date created: 21/07/2014
## Modified by: Raul Pelaez MRADDON
## Date modified: 03/05/2019
## Macro to count pages in the space.
## @noparams
## Settings
#set($containerManagerClass=$action.class.forName(‘com.atlassian.spring.container.ContainerManager’))
#set($getInstanceMethod=$containerManagerClass.getDeclaredMethod(‘getInstance’,null))
#set($containerManager=$getInstanceMethod.invoke(null,null))
#set($containerContext=$containerManager.containerContext)
## the spaceManager gives you access to the spaces
#set($spaceManager =$containerContext.getComponent(‘spaceManager’))
<h2>List of Spaces</h2>
<table class=”confluenceTable”>
<tr>
<th class=”confluenceTh”>Space Name</th>
<th class=”confluenceTh”>Page Count</th>
<th class=”confluenceTh”>Last Modified</th>
</tr>
#foreach($sp in $spaceManager.getAllSpaces())
#if($sp.isGlobal())
<tr>
<td>
<a href=”/display/$sp.getKey()”>$sp.getName()</a>
</td>
<td>
$spaceManager.findPageTotal($sp)
</td>
<td>
$sp.getLastModificationDate()
<!–$sp.getLastModifierName()–>
</td>
</tr>

#end
#end
</table>

</pre>

Macro based on this post

By MrAddon

 

Posted by:.

5 replies on “New Macro to show a list of spaces and pages and last modified date in Confluence

  1. Hello ,
    I tried with the above macro, But I am getting the following errors.
    Error rendering macro ‘pagecounter’

    Error occurred rendering template content

    Could you please help with this error.

    Thanks in advance

    Like

    1. Hello Rama,
      Just copy the code between PRE tags and paste in your Confluence Macro config section.
      Remember to replace the (“) characters by (“) correct ones… is a typical problem of WordPress pages (they process the content of the page and replace some parts)
      Regards

      Like

Leave a Reply to . Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s