Create title for blueprint index page dynamically

Hi,

I was wondering if there is a way to give the index page that gets created with a blueprint a title thats cerated dynamically. I want to create the title based on information the user enters in the wizard. I know how to do it for the actual blueprint page by using:

protected BlueprintContext updateBlueprintContext(BlueprintContext blueprintContext){

String pageTitle = "Some title";

blueprintContext.setTitle(pageTitle);

return blueprintContext;

}

How would I do something similar for the actual index page? This would also only occur the first time a blueprint is used in a space since that is the only time the index page is created. After that only the actual blueprint is is added to the space so I wouldn't need to change the name of the title.

3 answers

1 accepted

Accepted Answer
1 vote

Okay. Let's do this. Use the BlueprintListener class to call the onBlueprintCreateEvent. And add the following code to the onBlueprintCreateEvent method.

@EventListener
public void onBlueprintPageCreateEvent(BlueprintPageCreateEvent event)
{

Map<String,Object> blueprintContext = event.getContext();

String indexPageName = blueprintContext.get("IndexPage").toString();

Page page = event.getPage();

Page parentPage = page.getParent();

parentPage.setTitle(indexPageName);

}

Create an input box inside the wizard form with name and id "IndexPage". So when the blueprint is created, the Listener class will get whatever you input inside the IndexPage box, and set the title of the index page which is also the parent page of your blueprint. But the only catch here is, you'll have to figure out how to differentiate b/w the index page and a generic parent page. Perhaps you could parameterize the index page. Like everytime the index page is generated, it will have a constant name. So you can check if let's say the index page is always created by the name, "My Index", put a check that would see if the title of the parentPage is "My Index" then only set the title of the page. Else just ignore and don't do anything. Hope you get an idea of what I'm trying to say. Good luck :)

I think I understand what you are saying and will give it a shot. Thanks a lot for your help in this.

The index page I believe is only created when you create the page outside the parent page, lets say on the Dashboard. Might be a good idea to create the page you're trying to create on top of an existing page. That ways, the index page is never created. Else Confluence will pick up the name of the blueprint and create your page under it.

From the Dashboard I meant that Confluence does not know the parent page of the blueprint you're creating.

&lt;blueprint key="example" index-key="example" content-template-key="actual-template" index-template-key="my-index-page" &gt;

&lt;/blueprint&gt;

&lt;content-template key="actual-template"&gt;
&lt;resource name="template" type="download" location="/xml/actualTemplate.xml" /&gt;
&lt;/content-template&gt;
&lt;content-template key="my-index-page"&gt;
&lt;resource name="template" type="download" location="/xml/myIndex.xml" /&gt;
&lt;/content-template&gt;

You can use this to create your own index page if you want.

I am already creating my own index page but I just don't know how to give it a title dynamically from a java file. My blueprint has a form and then based on what the user puts in, creates a blueprint page with that info. I am able to dynamically create a title for the blueprint page in the java file but not the index page.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Featured Groups

Tuesday tips & tricks: What is the Atlassian Community?

It's officially Tuesday, which means it's officially time for another tip to help you better navigate this space we call the Atlassian Community. 😄 I got a great question from community member, Sa...

100 views 3 7
View post

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