Tags Reference

filter


A filter block allows you to call a filter with the contents of the block. Instead passing a value with the | syntax, the render contents from the block will be passed.

{% filter currency %}
order_item.price
{% endfilter %}

{# instead of {{ order_item.price | currency }}

for


A for loop allows you to perform an iteration over an array of objects and perform actions on each item. For example, let's say you wanted to loop over all of the customer's upcoming order items and print out the name of the product that is associated with each item. You can accomplish it by writing the following for loop

{% for order_item in order_items %}
  {% set product = product_by_id[order_item.product] %}
  <p>{{ product.name }}</p>
{% endfor $}

if - else


The if tag allows you test a condition and execute some code depending on the result of this test. One great example of this is marking an option as selected when the data matches to some hard-coded value.

{% if country_code === 'US' %}
  <option value='{{ country_code }}' selected>{{ countries[country_code] }}</option>
{% else %}
  <option value='{{ country_code }}'>{{ countries[country_code] }}</option>
{% endif %}

include


The include tag is used to pull other liquid partials into the area of your template. It's a very useful feature in helping you write template files which are smaller in size and are easier to maintain. Another useful part of this feature is the ability to use the same liquid partial in more than one place. For example, consider the need to render the customer's name in a stylized way above the order and inactive subscription sections. You can achieve it by creating a new liquid partial called customer-name.liquid and then using the include tag to render that content in both areas of the SMI

<h1 class="custom-name-badge">{{customer.name}}</h1>
{% include 'customer-name' %}
{% include 'customer-name' %}

raw


If you want to output any of the special Nunjucks tags like {{, you can use a {{, you can use a {% raw %} block and anything inside of it will be output as plain text.

{% raw %}
What a nice way to output some double {{
{% endraw %}
  
{# What a nice way to output some double {{

set


The set keyword allows you to modify or create new variables and set their value. For example:

{% set tutorials_rock = "Tutorials Rock!" %}
{% set product = product_by_id[order_item.product] %}

verbatim


{% verbatim %} has identical behavior as {% raw %}