Select Template in space blueprint
Asked by Ramon Segm?ller:

Is it possible to switch the used template in space blueprints?

I would like to create a space blueprint, which uses multiple possible templates, where the user can select one of them.

equivalent to this:

<https://developer.atlassian.com/server/confluence/write-an-advanced-blueprint-plugin/#step-1--choose-between-templates>

I used the input field from the example, but that didn't work.

The goal is to provide different space structures with child-pages. I managed to set these up, with help from this question:

<https://community.atlassian.com/t5/Answers-Developer-Questions/Blueprint-Page-template-with-child-pages/qaq-p/517413>

But I would like to be able to change the used template and hierarchy based on a user selection.


Answers:
author: Soumyadeep Mandal - SaM
body: Hi [@Ramon Segm?ller](/t5/user/viewprofilepage/user-id/4125311) ,

Please check if these resources are helpful

<https://community.atlassian.com/t5/Confluence-questions/Confluence-Blueprint-Select-users-in-the-create-space-dialog/qaq-p/1332046>

<https://community.atlassian.com/t5/Confluence-questions/Global-Templates-and-Blueprints/qaq-p/879614>

Regards,

***Soumyadeep***

comments: author: Ramon Segm?ller
body: Hi [@Soumyadeep Mandal - SaM](/t5/user/viewprofilepage/user-id/4216583) ,

This was unfortunately not what I searched for.

I wanted all that in a custom plugin. And found a solution. For anyone interested, the main components are:

Blueprint in atlassian.xml

```
<content-template key="my-space-homepage-template"
i18n-name-key="my.confluence.blueprints.space.homepage.name">
<description
key="my.confluence.blueprints.space.homepage.desc" />
<resource name="template" type="download"
location="/xml/my-home-page.xml" />
</content-template>

<space-blueprint key="my-space-blueprint"
i18n-name-key="my.confluence.blueprints.space.name" category="custom-category">
<content-template ref="my-space-homepage-template" />

<dialog-wizard key="my-space-blueprint-wizard">
<dialog-page id="mySpaceId"
template-key="My.Confluence.SpaceBlueprints.dialogForm"
title-key="my.confluence.blueprints.space.dialog.create.title"
description-header-key="my.confluence.blueprints.space.dialog.create.heading"
description-content-key="my.confluence.blueprints.space.dialog.create.description"
last="true" />
</dialog-wizard>

</space-blueprint>
```

A event listener, which reacts to the homepage creation:

```
@Named
public class BlueprintSelectionEventListener implements DisposableBean {


@ComponentImport
private final EventPublisher eventPublisher;

@Inject
public BlueprintSelectionEventListener(EventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
eventPublisher.register(this);
}

@EventListener
public void onSpaceBlueprintHomepageEvent(SpaceBlueprintHomePageCreateEvent event) {
String moduleCompleteKey = event.getSpaceBlueprint().getModuleCompleteKey();
if (MY_BLUEPRINT_KEY.getCompleteKey().equals(moduleCompleteKey)) {
String selectedTemplate = event.getContext().get("contentTemplateKey").toString();
useTemplate(selectedTemplate)
}
}




public void destroy() throws Exception {
eventPublisher.unregister(this);
}
}
```

And a selection in the soy template (similar to: <https://developer.atlassian.com/server/confluence/write-an-advanced-blueprint-plugin/#step-1--choose-between-templates>):

```
<select id="template-key-selector" class="select" name="contentTemplateKey">
? ?<option value="template_key">template description</option>
</select>,
```


Tags: confluence-development

confluence-server

server

space-blueprint