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

This widget could not be displayed.

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.

This widget could not be displayed.

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?

This widget could not be displayed.

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

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

This widget could not be displayed.

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

This widget could not be displayed.

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

This widget could not be displayed.

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

This widget could not be displayed.

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

This widget could not be displayed.

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 Sign up to answer
Community showcase
Published Friday in Jira

New 5k User Limit and Other Cloud Updates

Hi all! Lauren here from the Enterprise Cloud marketing team.  I have some exciting Cloud updates from #AtlassianSummit that I wanted to share. We want everyone in your organization to be ab...

89 views 0 2
Read article

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