I've been modifying an old user-macro (written using wiki mark-up, yes I'll update it to HTML soon!) and I'd like some help on how to use the API (class / methods) within a user-macro to extract some page metadata, which will be used to create a standard page header across an entire space (the information gathered is mostly listed within tools / page information).
The page metadata I'm looking for is:
I'm a little new to this, user-macro & API, but very familiar with confluence - so some gentle guidance on how to use the API within a user-macro would be very helpful. Explicit examples (or links) would be most appreciated!
FYI - I'm currently using the plugin "Page Information Tools" (by Adaptavist.com Ltd) to obtain this information, the intent being to reduce my dependency on this plugin by extracting my own metadata.
Community moderators have prevented the ability to post new answers.
Create a user macro with the following template code:
## @noparams <ul> <li><strong>Created By:</strong> #usernameLink($content.getCreatorName())</li> <li><strong>Created Date:</strong> $action.dateFormatter.formatDateTime($content.getCreationDate())</li> <li><strong>Page Version:</strong> $content.getVersion()</li> <li><strong>Last Modified By:</strong> #usernameLink($content.getLastModifierName())</li> <li><strong>Last Modifed Date:</strong> $action.dateFormatter.formatDateTime($content.getLastModificationDate())</li> </ul>
Hope this helps
Just use the PageManager to get the desired page object:
Get the page by id (replace "12345" with the id of the page):
#set($otherPage = $pageManager.getPage(12345))
Get the page by title (replace "SPACEKEY" with the key of the space and "Your Title" with the title of the page):
#set($otherPage = $pageManager.getPage("SPACEKEY", "Your Title"))
And then in the template code replace all occurences of $content with $otherPage. You could also replace the static page id with a dynamic macro parameter, as explained here.
@Remo Siegwart I tried using: ## @param ID:title=ID|type=string #set($otherPage = $pageManager.getPage($paramID)) But it does not manage to fetch the ID which I type in myself when using the macro. If I use $paramID it prints the ID fine. Just not within $pageManager.getPage($paramID)). Any advice?
You first need to convert the ID to an integer as pageManager.getPage() expects an integer as parameter, but paramID is a string. Here is how you could do it: ## @param ID:title=ID|type=string #set($Integer = 0) #set($otherPage = $pageManager.getPage($Integer.parseInt($paramID))) <p>Page title: $otherPage.title</p>
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events