Template

Template

{{ template }}

Name Type Description
object_type String Will always be datastore_item
is_valid Boolean True if this references a published template
guid String The unique identifier for this template
value String Contains the same value as guid
name text The name of the template which, when combined together with the path, uniquely identifies the template on this site
path String The path, exluding filename, of this template used for organizational and reference purposes
type select Field type (e.g., text, textarea, select, checkbox, etc.)
markup code Template markup/source code
field_id String The identifier for this field
label String The label for this field
output String Outputs the rendered template in a new child scope - similar to calling {% include %} with the current template.

{{ templates }}

Contains multiple templates.

Name Type Description
object_type String Will always be datastore_item
is_valid Boolean True if this contains at least one published template
output String The default output that the templates will produce when it is output directly to the template - using the "output_in_list" property of each template in the items list
prepended list List containing any prepended templates.
fetched list List containing all of the templates that were fetched from the database (as opposed to prepended or appended).
appended list List containing any appended templates.
appended_unique list List containing any appended templates excluding any templates that are in either the list of prepended or fetched templates.
items list List containing all of the combined templates from the prepended, fetched, and appended lists. If unique is true, this list will not contain any duplicates. If max_size is set, this list will not contain more than the number of templates specified.
size Integer The total number of templates in the items list, including prepended, fetched, and appended lists, and respecting the unique and max_size properties.
max_size Integer If set, this is the maximum number of items that will be returned in the items list and the maximum number of items that will be included when this templates object is enumerated as a list. When not set, this value will be 0.
unique Boolean When true, the items list will not contain any duplicates. Only the first instance of each template will be included.
limit Integer The maximum number of items that were allowed to be in the list of fetched templates. May be 0 in some cases (such as when when there are no fetched templates.
start Integer The 1-based index of the first item in the list of fetched templates.
page Integer The 1-based index of the paginated results returned in the list of fetched templates, which is calculated from the start and limit parameters. Useful for paginated results.
total_count Integer The 1-based index of the first item in the list of fetched templates
total_pages Integer

{% template %}

{% template output_to_template? [var, set, or assign]? variable? output_to_template? = value %}

{% template
output_to_template
 
If included the template will be output directly to the template.
var, set, or assign
 
Optional. Specify either "var", "set" or "assign" to change which scope this template is stored on. "var" is the default behavior.
variable_name
 
Specify a variable name in order to save this template to a variable. If not specified, it will be output to the template instead.
output_to_template
 
If included the template will be output directly to the template.
=
value
 
Should evaluate to a template object, or the name or guid of a template May use liquid filters.
%}
Fetches a single template.

{% templates %}

{% templates output_to_template? [var, set, or assign]? variable? output_to_template? = arguments %}

{% templates
output_to_template
 
If included the templates will be output directly to the template.
var, set, or assign
 
Optional. Specify either "var", "set" or "assign" to change which scope this templates is stored on. "var" is the default behavior.
variable
output_to_template
 
If included the templates will be output directly to the template.
=
arguments
 
Key:value pairs. May use the variable arguments syntax.
%}

arguments

prepend
 
May be a single template, a list of templates, or the name or guid of a template to be be included at the beginning of the templates.
append
 
May be a single template, a list of templates, or the name or guid of a template to be be included at the end of the templates.
exclude
 
May be a single template, a list of templates, or the name or guid of a template that should NOT be included in the fetched results. Has no affect on prepended or appended templates.
exclude_prepended
 
True to specifically exclude all prepended templates from the fetched results. If "unique:true" is specified this is the default behavior, although you may also specify "exclude_prepended:false" to allow any prepended items to be fetched along with other results anyway.
exclude_appended
 
True to specifically exclude all appended templates from the fetched results. This is false by default - even if "unique:true" is specified - so that results are returned in the proper order.
unique
 
True to remove duplicates from each of the resulting lists (prepended, fetched, appended, and items), although there may be duplicates between the prepended, fetched, and appended lists. The "items" list will include objects in the order in which they appear - with prepended items first, then fetched items, then appended items.
max_size
 
The maximum number of items to be included in the "items" list. If there are any prepended or appended items, this will automatically lower the "limit" to only fetch as many templates as needed. Note that this may also impact both the "page" and "total_pages" values in the resulting templates. In order to use pagination with a list loaded using "max_size" use "start" instead of "page" and "limit".
template_type
 
Only include templates with the given template type (page, partial, form, or gallery)
path
 
May include multiple paths. Only include templates with one of the given paths (excluding child paths)
date_created_start
 
Only include templates with date_created greater than or equal to date_created_start. Remember that date_created will typically be the date that the template was first published.
date_created_end
 
Only include templates with date_created less than or equal to date_created_end. Remember that date_created will typically be the date that the template was first published.
start
 
Set the 1-based index of the first template to fetch.
page
 
Used to automatically calculate the first template to fetch based on both the "limit" and the 1-based "page" value. Defaults to 1, but is ignored if "start" is set.
limit
 
The maximum number of templates to fetch. Defaults to 10. Note that if "max_size" is defined, then "limit" may be automatically lowered even if specified separately.
sort_by
 
Specify which property to sort the results by. Has no affect on prepended or appended templates. Options include:
  • date_created: the date each templates was first published. Unpublishing and republishing a templates resets date_created to the current date.
  • random: results will be returned in a random order, which prevents the page from being fast-cached. Setting cache_random:true overrides this behavior and allows the page to be fast-cached anyway.
  • name
  • title
  • url
  • browser_title
sort_direction
 
asc or desc.
cache_random
 
True to allow the results to be cached when sort_by is "random".
Fetches a list of templates.

Examples

Dynamically Include Template from a Select List

Copy
{% if page.page_layout.is_valid %}
<div class="sidebar-{{ page.page_layout.value }}">
{% let includeTemplate = "Sidebar-" | append:page.page_layout.value %}
{% include includeTemplate %}
</div>
{% endif %}

Dynamically Include Template from a Select List

Copy
{% if page.page_layout.is_valid %}
<div class="sidebar-{{ page.page_layout.value }}">
{% let includeTemplate = "Sidebar-" | append:page.page_layout.value %}
{% include includeTemplate %}
</div>
{% endif %}

Dynamically Include Multiple Templates from a Select List

Copy
{% if page.sidebar_sections.count > 0 %}
{% for section in page.sidebar_sections.selected %}
{% include section %}
{% endfor %}
{% endif %}

Checkbox Include Partial Template

Copy
<p>Show Sidebar? <strong>{{ page.show_sidebar }}</strong></p>
{% if page.show_sidebar.checked %}
{% include "Sidebar" %}
{% endif %}

Inline javscript from template

Copy
<script>{% include javascript "/javascript/inlined/blog" %}</script>
OR
{% javascript js = "/javascript/inlined/blog" %}
{% if js is_valid %}
<script>{% include js %}</script>
{% endif %}

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 %}