Include (Liquid tag)

From Shopify Wiki

Jump to: navigation, search

Introduction

The include tag lets you insert one of your theme's snippets into another layout, template, or snippet.

Usage

Given a snippet called foo.liquid that you have saved in your snippets folder:

{% include 'foo' %}

This will render foo.liquid with access to all the currently assigned variables and insert it within the parent template at the include tag's position. The optional with clause lets you specify a value which is bound to the snippet's name within the snippet's context:

{% include 'foo' with 'bar' %}

Examples

Within a snippet called color.liquid:

color: '{{ color }}'
shape: '{{ shape }}'

Within the theme.liquid layout:

{% assign shape = 'circle' %}
{% include 'color' %}
{% include 'color' with 'red' %}
{% include 'color' with 'blue' %}
{% assign shape = 'square' %}
{% include 'color' with 'red' %}

Output:

color: ''
shape: 'circle'
color: 'red'
shape: 'circle'
color: 'blue'
shape: 'circle'

color: 'red'
shape: 'square'