How to add default Page ID and prefix to page title

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

This widget could not be displayed.
Steven Behnke Community Champion Jul 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.

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

 

Thank you.

Ann Worley Atlassian Team Jul 13, 2017

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

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.

Ann Worley Atlassian Team Jul 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.

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.

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?

 

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!

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.

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.

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 ...

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!

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. ;-)

Ok perfect! I'll check it out.

 

Thank you so much for your help!

Steven Behnke Community Champion Jul 17, 2017

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

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. :)

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

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Monday in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

425 views 4 6
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you