Developers · Liquid
Liquid Tags: Include
Last updated 2 November 2026
The
The simplest example of
app/views/pages/include.liquid
{% include "mypartial" %}
<br/>
{% include "mypartial2" %}app/views/partials/mypartial.liquid
This is first partialapp/views/partials/mypartial2.liquid
This is second partialAfter expanding
This is first partial
<br/>
This is second partialYou can include the exact partial multiple times in multiple places for code reuse.
This article details the following topics:
- Passing parameters to a partial
- Local variable using with
- Iterating over a collection using for
- Using and exporting private variables
Passing Parameters to a Partial
You can pass any number of parameters to a partial.
app/views/pages/index.liquid
{% assign makers = "subaru,honda,toyota,suzuki,lexus" | split: "," %}
{% include "car", minYear: 2000, transmission: "auto", makers: makers %}app/views/partials/car.liquid
{{ minYear }} => 2000
{{ transmission }} => auto
{{ makers }} => ["subaru","honda","toyota","suzuki","lexus"]Tip
Put a space between the parameter name and its value, for example
Important
You cannot name a parameter the same as the partial (in this case
Local Variable using 'with'
Liquid has some issues when using a variable named the same as the partial. For example, if you have this
<p>This is the value of the variable called "car": {{ car }}<p>You won't be able to set the
{% assign cars = [{ "maker": "Honda", "model": "CRX" }] %}
{% include "car", car: cars[0] %}but you will be able to set this variable by using
{% assign cars = [{ "maker": "Honda", "model": "CRX" }] %}
{% include "car" with cars[0] %}This will create the variable called
{"maker"=>"Honda", "model"=>"CRX"}The properties of hash are accessible using the
{{ car["maker"] }} => HondaIterating over a Collection Using 'for'
{% assign cars = [
{ "maker": "Honda", "model": "CRX" },
{ "maker": "Subaru", "model": "Forester" },
{ "maker": "Lexus", "model": "LFA" }
] %}
{% include "product" for cars %}This will iterate over the collection and render the partial for each item. Each iteration will have the
A partial that looks like this:
app/views/partials/product.liquid
{{ product }}Will render (whitespace adjusted for readability):
{"maker"=>"Honda", "model"=>"CRX"}
{"maker"=>"Subaru", "model"=>"Forester"}
{"maker"=>"Lexus", "model"=>"LFA"}Using and Exporting Private Variables
In Insites, variables you create in a partial stay in that partial.
In Insites, when you define a variable in a partial, it is not visible by default on a page including that partial.
It works from top to bottom, though: If you define a variable on a page and then include it in a partial, it will be accessible in the partial.
That means that given this partial:
app/views/partials/variable.liquid
{% assign my_car = "Honda" %}And this page using it:
app/views/pages/include.liquid
{% include "variable" %}
This is empty: {{ my_car }}Will not return 'Honda' on the page. The
To use a variable that has been defined inside a partial, you need to use the
app/views/partials/export.liquid
{% assign honda = { "maker": "Honda", "model": "CRX", "year": "1991" } %}
{% export honda, namespace: "my_car" %}app/views/pages/include.liquid
{% include "export" %}
Car: {{ context.exports.my_car }}
My car maker: {{ context.exports.my_car.honda.maker }}This should render the stringified hash stored inside the variable in the first line and nested key in the second:
Car: {"honda"=>{"maker"=>"Honda", "model"=>"CRX", "year"=>"1991"}}
My car maker: Honda