Quantcast
Viewing all articles
Browse latest Browse all 12

Using and/or with if statements (conditionals) in the Liquid templating language

Just a quick thing here but a lot of times when I’m working on a Shopify theme and coding in the Liquid template language I forget the syntax to combine 2 if statements.

First, here is how you would write an if statement in Liquid.

{% template == 'index' %}
do something here...
{% endif %}

Now, if instead you want to check on whether 2 conditions are true, you could use the following syntax:

{% if template == 'index' and settings.show_image == 'yes' %}
do something here
{% endif %}

If you want to check whether just one of the conditions is true, then of course just change the and to or:

{% if template == 'index' or settings.show_image == 'yes' %}
do something here
{% endif %}

This syntax plus a whole lot of other Liquid syntax is documented on the Liquid page of the Shopify Wiki. I just wrote it down here to help myself remember it and maybe to save somebody else some time remembering or learning it later.


Viewing all articles
Browse latest Browse all 12

Trending Articles