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>
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<Page> #foreach( $child in $pagelist ) #set($p = $pageListArray.add( $child ) ) #if( $child.hasChildren() ) #process ( $child ) #end #end #end #process ( $spaceHome ) <table class="confluenceTable"> <tbody> <tr> <th class="confluenceTh">Title</th> <th class="confluenceTh">Version</th> <th class="confluenceTh">Mod Date</th> <th class="confluenceTh">Modifier</th> </tr> #foreach( $child in $pageListArray) ## child is of type Page <tr> <td class="confluenceTd">$child.getTitle()</td> <td class="confluenceTd">$child.getVersion()</td> <td class="confluenceTd">$child.getLastModificationDate()</td> <td class="confluenceTd">$child.getLastModifierName()</td> </tr> #end </tbody> </table>
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Would something like replacing
#set ($spaceHome = $space.getHomePage())
with
#set ($spaceHome = $context.getPage())
I cant seem to get this working.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
$rp is just the name of the argument in the process method. You could change it to whatever you want.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To format the date the way you want it, use something like this:
$action.dateFormatter.formatGivenString("dd-MMM-yyyy", $child.getLastModificationDate())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.