As you know, tags use programming logic to decide which dynamic content is displayed in your email. We’ve already experimented with the elsif/elsetag to choose content for our email based on the value of a key:
{% if pet.pet_type == "dog" %}
Ruff ruff! We’ve received your order!
{% elsif pet.pet_type == "cat" %}
Meow! We’ve received your order!
{% else %}
Hooray! We’ve received your order!
{% endif %}
Ruff ruff! We’ve received your order!
Just like filters, the tags you have available to you will depend on the flavor of Liquid you’re using, and there are lots of options. To give you a taste, here are some commonly used tags:
ifexecutes a block of code if your specified condition is met
elsif/elseallows you to set up alternative code for various conditions that might occur
forexecutes a block of code over and over again (this also called iteration)
assigncreates a temporary key or temporarily renames a key
Notation and operators
First, let’s recap the notation you’ll use for tags. As you learned in the Liquid Fundamentals lesson earlier, tags are surrounded by single curly brackets and percentage signs, like this:
{% tag %}
And because tags use logic to determine what content is displayed, they often contain operators to define that logic:
==
equals
!=
does not equal
>
greater than
<
less than
>=
greater than or equal to
<=
less than or equal to
or
logical or
and
logical and
contains
a particular string is present
A note about the containsoperator: itcan check for a particular string within a string or an array of strings. It can only search strings!
You’ll see some of these operators in use as we dive into types of tags (and we’ll dig deeper into some of the trickier ones later). As a general rule, tags fall into four broad categories: conditional, iteration, variable, and template.