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

How do you exclude the "Favourite" labels in a custom macro?

Ingrid S Talbot November 2, 2020

I have a macro that prints the labels on a page, so that I show display the labels above the fold in our knowledge base.

I've actually created two, which I have sourced from here and here.
Both work perfectly well, in that they print the labels on the page.

But.
I have recently noticed that when users have clicked "Save for Later", this then gets included as a label. In the one macro, this gets printed just as the word "favourite", in the other, it is printed as "my:favourite" (or the username of the person it not myself).

If multiple people have saved the page, then that many "favourites" appear in the macro.

Screenshot 2020-11-02 at 16.48.00.png

Question: How does one exclude the favourites?

(and why are these labels, in the first place?)

1 answer

1 vote
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.
November 2, 2020

I was unaware of these labels, but they make sense as an easy way to mark these pages.

To fix your issue, you are going to have to filter your output (test each label to see if it contains "favourite" before listing on a page.

Nicolas Casel
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.
July 2, 2021

Thanks @Bill Bailey , it works fine:

#foreach ($label in $content.getLabels())
#if ($label.getName() != "favourite")
<a id="clickable-label" class="aui-label" href="$req.contextPath/label/$space.key/$label.getName()">$label.getName()</a>
#end
#end

And it could be improved by using a ' while ' condition ;-)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events