v1.9.1
DeprecatedThis tag is deprecated, use render tag instead, which contains all the features of
includeand provides better encapsulation.
Include a Template
Renders a partial template from the template roots.
{% include 'footer.liquid' %} |
If extname option is set, the above .liquid extension becomes optional:
{% include 'footer' %} |
When a partial template is rendered by include, the code inside it can access its parent’s variables but its parent cannot access variables defined inside a included template.
Passing Variables
Variables defined in parent’s scope can be passed to a the partial template by listing them as parameters on the include tag:
{% assign my_variable = 'apples' %} |
The with Parameter
A single object can be passed to a snippet by using the with...as syntax:
{% assign featured_product = all_products['product_handle'] %} |
In the example above, the product variable in the partial template will hold the value of featured_product in the parent template.
Outputs & Filters
When filename is specified as literal string, it supports Liquid output and filter syntax. Useful when concatenating strings for a complex filename.
{% include "prefix/{{name | append: \".html\"}}" %} |
EscapingIn LiquidJS,
"within quoted string literals need to be escaped. Adding a slash before the quote, e.g.\". Using Jekyll-like filenames can make this easier, see below.
Jekyll-like filenames
Setting dynamicPartials to false will enable Jekyll-like includes, file names are specified as literal string. And it also supports Liquid outputs and filters.
{% include prefix/{{ page.my_variable }}/suffix %} |
This way, you don’t need to escape " in the filename expression.
{% include prefix/{{name | append: ".html"}} %} |