How to add default Page ID and prefix to page title

Anju July 12, 2017

My goal is to create a default page title for a specific template (kind of like the Meeting Notes template). I want to have the template type, page ID, and the title the user inputs.

So when a user creates a page using this specific template, the title should have: SPC-#### user input title

Note: The #### should be automatically generated once user creates the page.

What's the simplest way to achieve this? Also, what permissions would I need to have (Confluence admin or space admin)?

 

I was following a couple other discussions/questions regarding a default title but some suggested creating a custom blueprint and others said to change the custom HTML.

1 answer

1 accepted

0 votes
Answer accepted
Steven F Behnke
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 12, 2017

It's simply not possible out of the box. That's the easy answer. You need custom code of some variety to achieve this. Are you willing to write scripts or code of some type?

Are you on Confluence Cloud or Confluence Server. That will also dramatically change my answer.

Anju July 13, 2017

Yeah I'm willing to write scripts or code to achieve this. And I'm on Confluence Server.

 

Thank you.

AnnWorley
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 13, 2017

The Create from Template macro may be of help, please let me know if so.

Anju July 13, 2017

I'm not entirely sure if this would be what I'm looking for.

But I was wondering how would I put the page ID in the title. I tried @contentid and @pageid and that didn't work. Do you happen to know what I'd need to put instead to get the page ID?

 

Thanks.

AnnWorley
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 13, 2017

I couldn't pull the pageId either, I have a feeling its because it doesn't exist until the page is saved. We used to get pageId from the UI by checking the URL when in edit mode - Since Confluence 6, there is a draft ID in the URL and you have to go to Page Information and look at the URL for the page ID.

Anju July 13, 2017

Yeah I'll keep in mind the Create from Template macro, it's pretty neat.

But, I'm mainly trying to get the page ID to be in the title so that the page could be searchable using that ID. So, is there another way to do that?

 

Thank you.

AnnWorley
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 13, 2017

You cannot search for the page based on the pageId in the search bar but you can find it using CQL with a REST URL like:

Your_Confluence_URL/rest/api/content/search?cql=id=<pageID_number>

Here are the available fields:

CQL Field Reference 

I am getting really curious about your use case - why do you need to search by page ID?

 

Anju July 13, 2017

Hmm I will try it out. Just curious, would working with blueprints/creating my own blueprint be a possible solution to get the page ID in the title?

I'm using page ID because it's a unique number for each page and it's autogenerated. Ideally, what I want is to have every document have a prefix (i.e. SPC for specifications document), a unique number (page ID), and a page title. Like this:

SPC-1234 Page Title OR

SPC Page Title ID:1234

Because the ID is a unique number for each document, searching for that document would be optimal. If there was another way to autogenerate a unique number for each document, I would be open to trying that.

 

Thank you so much for your help!

Robert Reiner _smartics_
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 14, 2017

If you are writing your own blueprint you have full control over the title by providing a context provider.

Extending from 

com.atlassian.confluence.plugins.createcontent.api.contextproviders.AbstractBlueprintContextProvider

you have access to the blueprint context which contains the title.

BlueprintContext updateBlueprintContext(BlueprintContext blueprintContext)

This works per blueprint since you assign each blueprint its context provider. So to my knowledge you cannot contribute to an existing blueprint.

This enum lists common keys:

com.atlassian.confluence.plugins.createcontent.api.contextproviders.BlueprintContextKeys

Note that there is a key NO_PAGE_TITLE_PREFIX which deals with making titles unique by prefixing it. I haven't used it in my blueprints.

Anju July 17, 2017

So I extended AbstractBlueprintContextProvider and modified the updateBlueprintContext method and was able to add a String prefix. The String I input is automatically added to the title, which is good. But how would I pull the Page ID so that it can be added to the title?

 

Thank you.

Robert Reiner _smartics_
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 17, 2017

Sorry, I misunderstood that you need the page ID here (thought you have another source of IDs to pull from). The page ID is probably not generated in advance (but I do not know for sure). You probably would have access to the draft ID from the JavaScript context and could push it to the blueprint context (see Javascript API for blueprint wizards for details). But I do not know under which constraints these draft IDs are created.

You could probably have your own counter (for instance in an AO table or with Bandana) which would make you independent of the page ID. Or you could use the parent page ID  and add some number to it (like "-123" for the # child - use the Page Manager to check if the title already exists).

You could also listen to the page creation event and adjust the title then, but this seems a bit like a hack ...

Hope this helps ...

Anju July 17, 2017

Hmm I will check out AO and Bandana and see if it would work for me.

Also, while going through a tutorial on Soy Templates, I noticed the Page ID was generated. I'm thinking about looking into that too and seeing if it'll work.

 

Thank you!

Robert Reiner _smartics_
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 17, 2017

If the page ID is generated in the soy, then you probably have access to it via the JavaScript Blueprint API (the fields on the soy are propagated to the blueprint context). So the third option is still valid, too. ;-)

Anju July 17, 2017

Ok perfect! I'll check it out.

 

Thank you so much for your help!

Steven F Behnke
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 17, 2017

I wish that Robert had made his comment top-level answer! He deserves the "Answer" :)

Robert Reiner _smartics_
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 17, 2017

I think your answer sets the right context by showing all the aspects that need to be taken into consideration.  Therefore it deserves the "Answer"badge. I just contributed. No fault here. :)

Josep Riudavets
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!
October 13, 2017

Hello Anju, 

I'm trying to do exactly the same thing: automatically set the pageID as the prefix of the title when creating a new page. 

Did you finally achieve it? I'm trying to do this building my own blueprint but I wonder if there is another way to do it. 


Thanks

Josep

Like David Pressley likes this
Jan September 11, 2018

I am also looking for a solution similar to this. A page title prefix based on page ID or even better based on a page properties field content would be so helpful. The options in "create from template" macro are not sufficient

Like # people like this
Christina Georgieva
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!
May 21, 2024

Hi everyone, I am also looking for a solution similar to what @Anju describes in his comment above - we have a page template for Requirement specifications. Each page should get a prefix in the title containing an unique ID when it gets created. 

How can we do that? Is the solution of @Anju described somewhere? Or are there similar mor recent solutions for Confluence Cloud?

Many thanks in advance!

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events