Confluence Blueprint: How to choose blueprint template/xml file dynamically based on a condition selected in wizard

Hello,

I am writing a Confluence Blueprint. I have to have a wizard page to let user provide inputs. Here is what I did and I am able to see my template/xml being rendered on a page.

<blueprint key="custom-blueprint"
               create-result="edit"
               index-template-key="custom-blueprint-index"
               index-title-key="custom.blueprint.index.page.title"
               index-key="custom-blueprint"
               i18n-name-key="custom.blueprint.name">

        <content-template ref="custom-blueprint-content-template"/>

        <dialog-wizard key="file-list-blueprint-wizard">
            <dialog-page id="pickOptionSelectionPageId"
                         template-key="Custom.Blueprints.OptionSelectionTemplate"
                         title-key="custom.blueprint.dialog.option.select.template.title"
                         description-header-key="custom.blueprint.dialog.option.select.template.heading"
                         description-content-key="custom.blueprint.dialog.option.select.template.description"/>
            <dialog-page id="nextPageId"
                         template-key="..."
                         title-key="..."
                         description-header-key="..."
                         description-content-key="..."
                         last="true"/>
        </dialog-wizard>

    </blueprint>

    <content-template key="custom-blueprint-content-template"
                      i18n-name-key="custom.blueprint.content.template">
        <description key="custom.blueprint.content.template.description"/>
        <resource name="template" type="download" location="templates/custom-template.xml"/>
        <context-provider class="com.foo.CustomBPContextProvider"/>
    </content-template>

My requirement is to have few conditions on my wizard page, and based on the condition I need to select right template/xml file. I see xml template file is hardcoded within <content-template/> element in plugin.xml file.

Is there a way to select template file based on some condition ? OR if I can rewrite the xml file content on the fly to the existing template file.

Appreciate your help!

Thanks

1 answer

1 accepted

I acheived it by having a placeholder variable in my xml template file, and replacing the placeholder with the new xml on the fly.

template.xml:

&lt;at:var at:name="templatePlaceHolder" at:rawxhtml="true"/&gt;

MyContextProvider.java

if (includeA) {
            templatePlaceHolder = getTemplateFileAsString("/templates/A.xml");
        } else {
            templatePlaceHolder = getTemplateFileAsString("/templates/B.xml");
        }
...

blueprintContext.put("templatePlaceHolder", templatePlaceHolder);

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

359 views 20 10
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