Syntax Reference - leizongmin/tinyliquid GitHub Wiki

Output Variable: {{name}}

Example:

Hello, {{ name }}
Hello, {{ name | escape }}  // variable value to escape

Functions (Filters): {{value|method}}

Example:

Uppercase: {{ name | upcase }}
The time now is: {{ "now" | date: "%H:%M:%S" }}
Nesting: {{ name |  upcase | split: '-' }}
Get specific item index: {{ social_links | get:1  }}

Conditional: {%if condition%} ... {%else%} ... {%endif%}

Example:

{% if name == "old mine" %} Hello {{ name }} {% endif %}

{% unless name contains "Ray" %} not mine! {% endunless %}

{% if you.age < 18 %}
  You're too young
{% else %}
  Welcome to ...
{% endif %}

Note: The conditional operator can support equal to (==), not equal to (!= or <>), greater than (>), less than (<), greater than or equal to (>=), less than or equal to (<=), contains the string (contains).

Cycling: {%for item in array%} ... {%endfor%} {%tablerow item in array%} ... {%endtablerow%}

Example:

{% for item in array %}
  {{ item }}
{% endfor %}

{% for item in (1..10) %}
  {{ item }}
{% endfor %}

{% for item in array offset:2 limit:3 %}
  {{ item }}
{% endfor %}

{% tablerow item in array cols:4 %}
  {{ item }}
{% endtablerow %}

You can use variables for range (1..10), such as (1..num) and (start..end), for more detail see issue #32

Variable assignment: {%assign name = "value"%}

Example:

{% assign name = "value" %}

{% assign name = value | upcase %}

Save output to variable: {%capture name%} ... {%endcapture%}

Example:

{% capture name %}
  {% for item in array %}
    {% item %}
  {% endfor %}
{% endcapture %}

The output is saved to the variable *name* and you can output the results using: `{{ name }}`

Constant loop: {%cycle 'one','two','three'%}

Example:

{% cycle 'one', 'two', 'three' %},
{% cycle 'one', 'two', 'three' %},
{% cycle 'one', 'two', 'three' %},
{% cycle 'one', 'two', 'three' %} 

Output: one,two,three,one

Include file: {%include "filename"%}

Example:

{% include "header" %}

{% include "header" with data %}

Variables support: see issue #11

Do not interpret: {%raw%} ... {%endraw%}

Example:

{% raw %}{{ 5 | plus: 6 }}{% endraw %}

Output:

{{ 5 | plus: 6 }}

Comment (omitted from output): {%comment%} ... {%endcomment%}

Example:

Hello world. {% comment %} Now this is a single-line comment {% endcomment %} <br />
Hello world,
I think I'm gonna be happy today. {% comment %} Now this is a
multi-line comment that should be ignored too,
just like the single-line comment {% endcomment %}

Output:

Hello world.
Hello world, I think I'm gonna be happy today.

Syntax reference can be found here: http://wiki.shopify.com/Liquid

Extends: {% extends %} and {% block %}...{% endblock %}

see https://github.com/leizongmin/tinyliquid/issues/21

⚠️ **GitHub.com Fallback** ⚠️