Retrieving the label(s) of a particular page

johan milio September 7, 2018

Is it possible to retrieve the labels of one (1) particular page?

Say, I want to use the label(s) of a page as a value in a Page Properties key/value pair without having the editor putting that infomation in there manually (he only needs to add the label to the page).

Is this possible with standard Confluence functionality?

2 answers

1 accepted

1 vote
Answer accepted
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.
September 12, 2018

Well if by "standard" Confluence functionality, you include user macros, then yes. If you are comfortable with VTL and Java methods, the two you would need would be the getPage() and getLabels() (the last returns a collection).

johan milio September 13, 2018

Thanks Bill, this answers my question... 

But I don't know how to write a user macro, so I guess there is no way of obtaining what I was asking for with my standard confluence configuration.

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.
September 13, 2018

Well there are guides, and samples out there. There is also a complex sample that deals with labels here:

https://github.com/unidwell/confluence-include-child-pages-macro

And yes there is a learning curve, but user macros allow you to fill in the holes in Confluence. And when I started, I knew nothing about VTL or Java. ;-) So it will take time to create this first macro, but the time will pay dividends later.

johan milio September 13, 2018

thanks! 

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.
May 27, 2021

Thanks @Bill Bailey  for this insight ; I am a bit familiar with user macros, but not enough to write a full one from scratch ... Could you elaborate a bit more about how to use the getPage() and getLabels() functions?

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.
June 2, 2021

If you look at this code:

https://github.com/unidwell/confluence-include-child-pages-macro/blob/master/include_pages_macro.vm 

You will see examples.  The author first calls the needed functions:

#set( $pageManager=$containerContext.getComponent('pageManager') )

Now the methods can be accessed. So for example:

#set( $currentPage = $pageManager.getPage($content.id) )

Then you can do something like this

#set( $labels = currentPage.getLables( ))

 

Spend some time breaking down how the autor constructed the macro will help a lot in learning these tricks.

Like Nicolas Casel likes this
0 votes
Victor Mutambuki
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.
September 7, 2018

Johan,

If you create a template and give it a label, any pages that are created using the template will automatically be created with that label.

Blue Prints and User created Templates

Victor

johan milio September 8, 2018

Hi Victor,

thanks for the response, however, that is not the answer i'm seeking..

In fact, I want to know if it is possible, using standard Confluence functionality, to retrieve the label on a page automatically in a Page Properties field on that same page, so that i can report that label in the table that is automatically generated by a Page Properties Report macro.

I want to avoid that people need to add the label and secondly, the same label information in a properties field.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events