{% include %}

Processes a partial template. Any variables in the parent template will be available in the partial template. Variables set from the partial template using the set or assign tags will be available in the parent template.

If the partial template is a compiled template, then any custom fields from the partial template will be available in the parent template as well.

Syntax

{% include template [variable1: value] [variable2: value] [etc...] %}

template: Can either be a string or a variable. Note that templates included from variables are not "compiled templates" and therefore any custom fields defined in them will not be available from the parent template. If template is a string, the template to be included will be dependent on both the current and target template's path. More on that below.

variables: Include variables for assignment in the {% include %} tag. This is identicial to calling {% var %} on the variables inside the template except that you cannot use filters in the include tag variable assignment. You can even assign varaibles by reference.

The include tag creates a new child scope.

Path

The path is significant when including partial templates. Every template has a path, even if that is the root path (/). The location of the path to be included will always be based off of the path of the current template. So including 'header' from a template at the path '/pages' will attempt to process '/pages/header' while the same include from a template at the root path - which would attempt to process '/header'.

You always have the option of using an "absolute path" when including templates by beginning your included template name with '/'. Eg: {% include '/header' %} or {% include '/partials/header' %}. Absolute paths ignore the path of the current template when determining what partial to include.

You can also navigate up the directory structure using '../'. So including '../partials/header' from a template at the path '/agency/pages' will attempt to process '/agency/partials/header'.

Examples

Include partial by string

Copy
{% include "/partials/header" %}

Dynamically Include Template

Copy
{% var dynamicTemplate = "/partials/footer-main" %} {% include dynamicTemplate %}

Include template and pass variables

Copy
{% search searchCollection "keyword" limit:10 page:search-page %} {% for result in searchCollection %} {% include "search-result" item:result %} {% endfor %} {% include "pagination" collection:searchCollection style:"links" max_links:5 %}