I am writing a user macro to get a list of pages with a specific label.
This is the code that I have written. But it does not return anything. Do you know what's wrong with the code? how can I use the labelManager in a user macro?
## Macro title: My Macro
## Macro has a body: Y or N
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: My Name
## Date created: dd/mm/yyyy
## Installed by: My Name
## This is an example macro
## @Param Label:title=Label|type=string|required=true|desc=Input one label
#set($containerManagerClass=$action.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager=$getInstanceMethod.invoke(null,null))
#set($containerContext=$containerManager.containerContext)
#set($labelManager=$containerContext.getComponent('labelManager'))
##set($pages = $labelManager.getContentForLabel($labelManager.getLabel($paramLabel), 10))
<span>
#foreach( $page in $pages )
<span class="aui-label">$page.name</span>
#end
I made a mistake..I had an extra character # in the $pages parameter definition.
I am writing a user macro to get a list of pages with a specific label.
This is the code that I have written. But it does not return anything. Do you know what's wrong with the code? how can I use the labelManager in a user macro?
## Macro title: My Macro
## Macro has a body: Y or N
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: My Name
## Date created: dd/mm/yyyy
## Installed by: My Name
## This is an example macro
## @Param Label:title=Label|type=string|required=true|desc=Input one label
#set($containerManagerClass=$action.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager=$getInstanceMethod.invoke(null,null))
#set($containerContext=$containerManager.containerContext)
#set($labelManager=$containerContext.getComponent('labelManager'))
#set($pages = $labelManager.getContentForLabel($labelManager.getLabel($paramLabel), 10))
<span>
#foreach( $page in $pages )
<span class="aui-label">$page.title</span>
#end
No Idea if this is still needed, but you could use
#set( $labelManager = $action.getLabelManager())
to get the labelmanager for a user macro
$action is the ConfluenceActionSupport, which is provided within the velocity templates by confluence (https://developer.atlassian.com/server/confluence/confluence-objects-accessible-from-velocity/), and holds a labelManager object (https://docs.atlassian.com/ConfluenceServer/javadoc/7.11.1/com/atlassian/confluence/core/ConfluenceActionSupport.html)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.