Snippets
If you need to share code between Templates, you can define snippets in the Snippets page.
The name you give a Snippet is how you will refer to it later on in your Templates.
Let's define two snippets:
Snippet: user-name
{%- if userName -%}
{{userName}}
{%- else -%}
Someone
{%- endif -%}
Snippet: items-list
{%- for item in list -%}
<p>{{item}}</p>
{%- endfor -%}
You can then load them in a Template like follows:
Template
{%- load_snippets 'user-name', 'items-list' -%}
<p>Hello {% include 'user-name', userName: "Jane Doe" %}</p>
{% include 'items-list', list: user.groceries %}
Copy link