Can anyone assist creating a user macro

Can anyone assist me creating a user macro that will create a table displaying every page in a space with the following details

Page Title

Version

Last modified date

Changed By

At the moment i have the following random code, i think i need to create a do while loop that will search out each page and return with the informtion required and place it into a row in a table

## @noparams
## Macro name: DisplayChildRevision
## Generates: HTML Markup

#set($childPageTitle = $childPage.getTitle)
#set($childPageVersion = $childPage.getVersion)
#set($childPageDate = $childPage.getLastModificationDate)
#set($childPageAuthor = $childPage.getLastModifier)
#set($anyKids = $action.hasChildren())
#set($kids = $root.getSortedChildren())


<div id=”document-revision-div”>
<table class="document-revision-table">

<tr>
<th>Child Page title</th>
<th>Child Page version</th>
<th>Child Date</th>
<th>Child Changed by</th>
</tr>

<tr>
<td>$childPageTitle</td>
<td>$childPageVersion</td>
<td>$childPageDate</td>
<td>$childPageAuthor</td>
</tr>

</table>
</div>

8 answers

1 accepted

Here you go:

## Macro title: Page Data
## Macro has a body: N
## Body processing: n/a
## Output: HTML
##
## Developed by: Matthew J. Horn
## Date created: 06/27/2013
## @noparams

#set ($pageListArray = [])
#set ($spaceHome = $space.getHomePage())

#macro ( process $rp )
  #set ($pagelist = $rp.getSortedChildren() )  ## returns List&lt;Page&gt;
  #foreach( $child in $pagelist )
    #set($p = $pageListArray.add( $child ) )
    #if( $child.hasChildren() )
      #process ( $child )
    #end
  #end
#end

#process ( $spaceHome )


&lt;table class="confluenceTable"&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
  &lt;th class="confluenceTh"&gt;Title&lt;/th&gt;
  &lt;th class="confluenceTh"&gt;Version&lt;/th&gt;
  &lt;th class="confluenceTh"&gt;Mod Date&lt;/th&gt;
  &lt;th class="confluenceTh"&gt;Modifier&lt;/th&gt;
 &lt;/tr&gt;

 #foreach( $child in $pageListArray)   ## child is of type Page
   &lt;tr&gt;
     &lt;td class="confluenceTd"&gt;$child.getTitle()&lt;/td&gt;
     &lt;td class="confluenceTd"&gt;$child.getVersion()&lt;/td&gt;
     &lt;td class="confluenceTd"&gt;$child.getLastModificationDate()&lt;/td&gt;
     &lt;td class="confluenceTd"&gt;$child.getLastModifierName()&lt;/td&gt;
   &lt;/tr&gt;
 #end 

&lt;/tbody&gt;
&lt;/table&gt;

You sir are a gent, If i wanted to change it so rather than searching the entire space for child pages. its only did it from the current page where the macro is applied.

How can this be done?

Would something like replacing

#set ($spaceHome = $space.getHomePage())

with

#set ($spaceHome = $context.getPage())

I cant seem to get this working.

Changing it to

#set ($currentPage = $action.page)

will allow the macro to only search child pages below the page on where the macro is applied.

Im now having trouble formatting the date to the standard format we are using

DD-MMM-YYYY (23-May-2013)

i currently have Mar 26, 2013 14:25, using the following peice of code.

#set ($PageDate = $action.dateFormatter.formatDateTime($content.lastModificationDate))

How is it possible to format the date?

To format the date the way you want it, use something like this:

$action.dateFormatter.formatGivenString("dd-MMM-yyyy", $child.getLastModificationDate())

As for just working with the current page its children (rather than the entire space), just replace the #process($spaceHome) with #process($content).

The $content object, when the macro is used directly in a page, refers to the current Page object.

hth,

matt

What is $rp, it doesnt seem to run on space export.

$rp is just the name of the argument in the process method. You could change it to whatever you want.

Matthew, how would I turn $child.getTitle() into a link that can be clicked to that page? Thanks.

You can use $child.getUrlPath() or $child.getLinkWikiMarkup() to build a link to the page in your table.

The $child var is of type Page so you can use any methods of Page or its parent classes. The full API is here:

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

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,899 views 12 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot