Sharing simple.ftl across profiles

Managed by | Updated .

Background

This article outlines the steps required to share a template across multiple profiles within a collection.

Share a template using import directives

Freemarker's <#include> directive can be used to nest the content of another Freemarker template within a template file. This allows a simple template to be created that nests a shared template.

Example: share the collection's default template with other profiles.

Step 1: Create the template to be shared

Customise the default template for the collection by designing the results page for the _default profile.

Step 2: Include the template from another template

Switch to the profile with which the template should be shared and edit the template file.

Delete all the existing template code and replace with the following include statements:

<#ftl encoding="utf-8" />
<#if question.profile?exists>
    <#if question.profile?matches(".*_preview")>
        <#include "../_default_preview/simple.ftl">
    <#else>
        <#include "../_default/simple.ftl">
    </#if>
<#else>
    <#include "../_default/simple.ftl">
</#if>

This will cause Funnelback to use the _default/simple.ftl for the live view of myprofile and _default_preview/simple.ftl for the preview view of myprofile when rendering out the template.

Conditional logic could also conceivably be used to set some variables that are read from the shared template.

If a user wishes to override the default shared template this code can be deleted and new custom template code used.

It is also possible to share templates by using symbolic links. However, this is not recommended because it is not clear to a user editing a template that they are actually editing a shared template. This means a user can easily customise a shared template without realising that their changes may affect other templates on the system.

Further reading

Was this artcle helpful?

Tags
Type: Keywords:
Features: Frontend > Templating Frontend > Freemarker

Comments