It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

1 vote
Answer accepted

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
TAGS
Community showcase
Posted in Confluence

Lessons and Learnings: Six Months of Working Remote [Discussion]

Hey there, folks! For most of us, the past six months- yes, you read that right- have been a journey. More people than ever before have pivoted to working remotely, and navigating being on-scre...

3,138 views 4 6
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you