Tags Information

Tags

Liquid tags are the programming logic that tells templates what to do. Tags are wrapped in: {%  %} characters.
Certain tags, such as for and cycle can take on parameters. Details for each parameter can be found in their respective sections under Objects.

Control Flow

Control flow tags create conditions that decide whether blocks of Liquid code get executed. You can use Operators to determine the true/false of the conditions. Multiple conditions can be considered by using  and and or in the statements.

if
Executes a block of code only if a certain condition is met (if the result is true).

{% if sponsorship.sponsorship_type.permalink == 'children' %} 	Let's talk about the Children sponsorship type. {% endif %}

else / elsif
Adds more conditions to an if block.

{% if sponsorship.sponsorship_type.permalink == 'children' %} 	Let's talk about the Children sponsorship type. {% elsif sponsorship.sponsorship_type.permalink == 'teachers' %} 	Let's talk about the Teacher sponsorship type. {% else %} 	Let's talk about something else. {% endif %}

unless
Like if, but executes a block of code only if a certain condition is not met (that is, if the result is false).

{% unless sponsorship.sponsorship_type.permalink == 'children' %} 	Let's talk about something else besides the Children sponsorship type. {% endunless %}

case / when
Creates a switch statement to execute a particular block of code when a variable has a specified value. case initializes the switch statement, and when statements define the various conditions.
You can optionally add an else statement at the end of the case to provide code to execute if none of the conditions are met.

{% case sponsorship.sponsorship_type.permalink %} {% when 'children' %} 	Let's talk about the Children sponsorship type. {% when 'teachers' %} 	Let's talk about the Teacher sponsorship type. {% else %} 	Let's talk about something else. {% endcase %}

Iteration

Iteration tags repeatedly run blocks of code.

for
Repeatedly executes a block of code. You can then access attributes available for each object.

{% for sponsorship in sponsorships %} 	{{ sponsorship.title }} {% endfor %}

cycle
Loops through a group of strings and outputs them in the order that they were passed as parameters. Each time cycle is called, the next string that was passed as a parameter is output.
cycle must be used within a for loop block.

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

Theme

Theme tags interact with the theme files you have developed.

include
Inserts a partial from the partials section of a theme.

{% include 'my-partial' %}

javascript_tag
Inserts a javascript asset from the theme.

{% javascript_tag | example %}

stylesheet_tag
Inserts a stylesheet asset from the theme

{% stylesheet_tag | example %}

asset_url_tag
Returns a generic asset url from the theme.

{% asset_url_tag  | example.jpg %}

Was this article helpful?

Previous Article

Liquid Objects

Next Article

Filters