automatically adding labels to confluence page

Paul DeSousa
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.
March 24, 2015

Hi all,

Is there a way to automatically add a label to a page upon creation.  We are wanting to create a retention policy for our site that has a number of settings.  For each space we would want a default retention policy label applied to each page.  So:

Space A: all pages default to rrpolicy1

Space B: all pages default to rrpolicy2

Space C: all pages default to rrpolicy1

I can, with the cli, add a label to each page in a give space through a programmatic method, but newly created pages will not automatically get the new label.

Thanks in advance,

Robert

 

6 answers

1 accepted

2 votes
Answer accepted
mlavender
Contributor
March 24, 2015

Hi Robert

You can do this. What you will want to do is create a new page template within each space. In the template you would include any labels that you wanted. Once created you can click the 'promote' link which will cause the template to be at the top of the list of options when creating a new page.

When someone goes to create a new page within this space, they would simply choose this template to create their page, and the correct labels would automatically be added.

I hope this is what you were looking for.

Cheers
Marty

Paul DeSousa
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.
March 24, 2015

Is there a way to edit the default templates to simply add a label to them? I really do not know how to recreate the Blog post, decision, etc. pages so that there is a duplicate of each one with a new label. Also is there a way when the page is created to not allow the users to delete the label? IE can I lock the label?

Rodney
Contributor
September 10, 2019

There is currently no way to add a label to a template in the cloud version in 2019.  I checked over and over. I know how to add a label multiple ways to a page manually created from a template. However, none of those options exist in the editing / creating a template editor.

However, Confluence has a number of pages that come from templates that have labels that are auto-applied when the page is created. This is kind of important if you want these pages you create from a template to automatically show up in "Page Properties Report" which are label driven.  

Please whoever replaced Marty share an update on how to do this? Also on a related note, your cloud docs are out of date on the creating of a template as they don't align with the cloud we are using and I assume we are always on the same version since its the "cloud".

Like # people like this
3 votes
TLenz
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 27, 2018

If you are creating a page from a template, then yes, it can automatically label the page. Click the gear cog in the bottom left and then click Content Tools. At the top of that page should be your user created templates. Click Edit for the appropriate template. Once you are editing the template, there is a little tag icon next to the page title. By clicking that you'll get a modal window with free form text entry. Type your text and select the appropriate tag.

 

Now each time you create a page using that template, your page will be automatically tagged with that label.

Peter_Baschan
Contributor
October 3, 2018

Simple and great solution! :)

2 votes
Midori
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.
March 25, 2015

You could also solve it by building a dead-simple Confluence plugin that contains nothing else but an EventListener. The listener should intercept the "page created" events and add the labels trivially.

Another option to consider is to use the Archiving Plugin to implement your retention policies, instead of rolling out some custom solution. With this you can set up policies per space, according to your requirement. Make sure you check it.

An older screenshot about the config options:

confluence-retention.png

Paul DeSousa
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.
March 25, 2015

I do need to learn to write plugins so that sounds like a good solution as well. As far as the archive plugin, I believe that only archived pages not comments and we are interested at first in only deleting comments.

1 vote
Alexey Matveev
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 13, 2018

Hello,

You could use the Power Scripts add-on:

https://marketplace.atlassian.com/apps/1219507/power-scripts-for-confluence?hosting=server&tab=overview

You could write a listener for the Page Create event with this code:

if (space == "your space key") {
labels = {"yourlabel"};
}

This listener would add a label to each page, which is create in the required space.

You can find more info about listeners here:

https://confluence.cprime.io/pages/viewpage.action?pageId=32825901

Martijn Wouda
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 5, 2019

would this also help when importing pages from a word document?

1 vote
Stephen Deutsch
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.
March 24, 2015

Another option would be to install the Label Tools addon from Adaptavist (https://marketplace.atlassian.com/plugins/com.adaptavist.confluence.labeltools), which contains the add-label macro.

Then you would need to get this to display on every page in the space.  If you are still using the documentation theme, then you can just add the macro in wiki markup format in either the header or the footer: 

{add-label:rrpolicy1}

Or, if you are using the default theme, you will need to change the page layout for the space and add the following line somewhere in the decorator:

$action.helper.renderConfluenceMacro("{add-label:rrpolicy1}")

Then newly created pages should have the label added to them.

Stephen Deutsch
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.
March 24, 2015

If you don't want to use the Label Tools plugin, I could whip up a user macro that adds a label to the page using javascript, but since it's already there...

Paul DeSousa
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.
March 24, 2015

I have no problem installing the plug in, especially since it's free. :) Where do I go to edit the header or footer? If I just changed the layout (I do that a lot already) wouldn't that be for all spaces? Ideally I would like a different setting per space.

Paul DeSousa
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.
March 24, 2015

Ideally I would like to mark both answers as correct as they both solve the problem to an extent, but when I mark the above answer as correct is deactivates this one and vise versa...

TomC
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 24, 2015

Robert, I have encountered the same issue both asking and answering questions. It may be a viable enough issue to place a feature request on it for Confluence Questions (I haven't searched if it already is, but if it is I'll vote for it!).

0 votes
Arthur Mack
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 13, 2023

Yes, just set up a confluence automation rule for each space that adds a label to a new page. when its created.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events