Sharing simple.ftl across results pages

This article outlines the steps required to share a Freemarker template across multiple results pages within a search package.

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 a template amongst results pages

Step 1: Create the template to be shared

Create a results page for your shared template. e.g. create a results page called shared then customize the template within the shared results page.

Step 2: Include the template from another template

Switch to the results page (e.g. example) 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 "../shared_preview/simple.ftl">
    <#else>
        <#include "../shared/simple.ftl">
    </#if>
<#else>
    <#include "../shared/simple.ftl">
</#if>

This will cause Funnelback to use the shared/simple.ftl for the live view of myprofile and shared_preview/simple.ftl for the preview view of example 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 customize a shared template without realizing that their changes may affect other templates on the system.

Further reading