How to add default Page ID and prefix to page title
Asked by Anju:

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.


Answers:
author: Steven F Behnke
body: 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.

comments: author: Anju
body: Yeah I'm willing to write scripts or code to achieve this. And I'm on Confluence Server.

Thank you.


author: AnnWorley
body: The [Create from Template](https://confluence.atlassian.com/doc/create-from-template-macro-317196995.html) macro may be of help, please let me know if so.


author: Anju
body: 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.


author: AnnWorley
body: 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.


author: Anju
body: 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.


author: AnnWorley
body: You cannot search for the page based on the pageId in the search bar but you can find it using [CQL](https://developer.atlassian.com/confdev/confluence-server-rest-api/advanced-searching-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](https://developer.atlassian.com/confdev/confluence-server-rest-api/advanced-searching-using-cql/cql-field-reference#CQLFieldReference-idIDID)

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


author: Anju
body: 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!


author: Robert Reiner _smartics_
body: 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.


author: Anju
body: 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.


author: Robert Reiner _smartics_
body: 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](https://developer.atlassian.com/confdev/confluence-plugin-guide/confluence-blueprints/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](https://developer.atlassian.com/docs/atlassian-platform-common-components/active-objects) table or with [Bandana](https://developer.atlassian.com/confdev/development-resources/confluence-developer-faq/what-is-bandana-one-form-of-confluence-persistence)) 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 ...


author: Anju
body: 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!


author: Robert Reiner _smartics_
body: 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. ;-)


author: Anju
body: Ok perfect! I'll check it out.

Thank you so much for your help!


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


author: Robert Reiner _smartics_
body: 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. :)


author: Josep Riudavets
body: 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.

<br />

Thanks

Josep


author: Jan
body: 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


author: Christina Georgieva
body: Hi everyone, I am also looking for a solution similar to what [@Anju](/t5/user/viewprofilepage/user-id/1140034) describes in his [comment above](https://community.atlassian.com/t5/Confluence-questions/Re-Re-How-to-add-default-Page-ID-and-prefix-to-page-title/qaq-p/609319/comment-id/81535#M81535) - 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!