Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to reference the label's link of a page in a user macro?

Peter_Baschan October 1, 2018

Hi,

I want to show a page label within the content the same way as it appears at the bottom of the page. I got to the stage where the labels are displayed following this suggestion by Steve (https://community.atlassian.com/t5/Answers-Developer-Questions/Is-there-a-way-to-place-a-list-of-the-page-s-labels-in-a/qaq-p/570841), but the rendered labels are simple text, not hyperlinks. My code is the following:

## Macro title: Page labels
## Macro has a body: N
## Body processing: No macro body
##
## Developed by: Steve Behnke

## @noparams
#set($currentPage = $pageManager.getPage($content.getId()))
#set($pageLabels = $currentPage.getLabels())
<span>
#foreach( $labelObject in $pageLabels )
<span class="aui-label">$labelObject.name</span>
#end
</span>

I guess the link element should go into the #foreach section, but I don't know how. Any help is much appreciated.

 

Many thanks,

Peter

 

1 answer

1 accepted

1 vote
Answer accepted
Thomas Schlegel
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 1, 2018

Hi @Peter_Baschan,

this should work:

 

 #foreach( $labelObject in $pageLabels )
<span class="aui-label">
<a class="aui-label-split-main" href="/label/$space.key/$labelObject.name" rel="tag">$labelObject.name</a>
</span>
#end

 

Bill Bailey
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 2, 2018

Yes that should work. I built a similar structure for a macro recently.

Peter_Baschan October 3, 2018

Works like a dream. Many thanks! :)

Thomas Schlegel
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 3, 2018

You’re welcome, @Peter_Baschan

Winfried Mühl March 7, 2021

!! Thanks a lot to @Thomas Schlegel !!
I just introduced this nice little macro in our Confluence instance!

It will be very helpful!

Like Thomas Schlegel likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events