Syntax Tags
Syntax tags control how Liquid code is processed and rendered.
comment
Stops an expression from showing or being output. Text inside comment tags will not be shown, and Liquid code inside will be read but not run.
content
{%- endcomment -%}
Inline comments
Inline comments stop code inside {% %} tags from being shown or running.
Use inline comment tags to add notes to your code or to stop parts of your code from running temporarily.
You can make multi-line inline comments, but each line must start with a # to avoid syntax errors
{%- # for i in (1..3) -%}
{{ i }}
{%- # endfor -%}
{%- ############################### -%}
{%- # This is a comment -%}
{%- # across multiple lines -%}
{%- ############################### -%}
Inline comments inside liquid tags
You can add inline comments within liquid tags. Each comment line requires its own tag.
# this is a comment
assign topic = 'Learning about comments!'
echo topic
-%}
echo
Outputs an expression.
Using the echo tag displays the result of an expression. It functions similarly to enclosing an expression in double curly brackets ({{ and }}
). However, the echo tag offers the advantage of compatibility within liquid tags.
Note: You can apply filters to expressions within echo tags.
echo expression
-%}
{%- liquid
echo product.price | money
-%}
Liquid
Allows you to use a block of Liquid without separators around each tag. Since tags lack separators, each one must stand alone on its own line.
Note: Use the {{ }}
tag to display a value within liquid tags.
expression
-%}
The content that will appear within the liquid tag.
# Show a message that's customized to the product type
assign product_type = product.type | downcase
assign message = ''
case product_type
when 'health'
assign message = 'This is a health potion!'
when 'love'
assign message = 'This is a love potion!'
else
assign message = 'This is a potion!'
endcase
echo message
-%}
raw
The content to display within the liquid tag.
expression
{%- endraw -%}
The value to display without displaying it on the screen.
{{ 2 | plus: 2 }} equals 4.
{%- endraw -%}