Hi
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.
Kind Regards
Gavin.
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>
Hints:
Hope this helps
Excellent - exactly what i was looking for. Many thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Remo: But what if I want to get info about other page. It is... bind $content (or other variable) to other page than the one where the macro is being executed.
Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
Late to the party, but want to say thanks @Remo Siegwart. I created a user macro with this and it solved my requirement.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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 must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Remo Siegwart Perfect! Works wonderful. The string/integer is above my code knowledge, but as long as it works I'm happy :]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I also need this feature, did you find something else?
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.