Forums

Articles
Create
cancel
Showing results forĀ 
Search instead forĀ 
Did you mean:Ā 

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

Peter Baschan
Contributor
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 Champion
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 Champions.
October 2, 2018

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

Peter Baschan
Contributor
October 3, 2018

Works like a dream. Many thanks! :)

Thomas Schlegel
Community Champion
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