Can anyone assist creating a user macro

Deleted user June 26, 2013

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

5 votes
Answer accepted
Matthew J. Horn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2013

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;

Deleted user July 2, 2013

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?

Deleted user July 2, 2013

Would something like replacing

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

with

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

I cant seem to get this working.

0 votes
Matthew J. Horn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 16, 2013

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

0 votes
Alan October 16, 2013

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

0 votes
Matthew J. Horn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 14, 2013

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

0 votes
Mango ICT August 14, 2013

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

0 votes
Matthew J. Horn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 1, 2013

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

0 votes
Matthew J. Horn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 1, 2013

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

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

0 votes
Deleted user July 7, 2013

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?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events