Skip to main content

A question on conditionals

I understand conditionals like: 

{% if page.slug == "pageslugname" %}
{% else %}
{% endif %}

I also understand the nested variety:

{% if page.slug == "pageslugname" %}
     {% if page.slug == "otherpageslugname" %}
     {% endif %}
{% else %}
     {% if page.slug == "yetanotherpageslugname" %}
     {% endif %}
{% endif %}

But what if I want to do OR ?  How do I code this: 

If A OR B OR C 
{% else %}
{% endif %}

I would also like to know what is the code for children?

{% if page.slug == child of slug name %}
{% else %}
{% endif %}

 

If this is covered in the theme documentation, then I missed it. If so, could you send me a link to where it's in the theme documentation? 

Thanks!

Official response from

Hi Tim,

You can find additional documentation about If / Else conditional statements in liquid here. On that link you'll see these examples:

{% if user.name == 'tobi' %}
Hello tobi
{% elsif user.name == 'bob' %}
Hello bob
{% endif %}

 

{% if user.name == 'tobi' or user.name == 'bob' %}
Hello tobi or bob
{% endif %}

 

Also, you can find the variables for page children in the theme docs here, but you can look at a good example by digging into the code on the FAQ page type, where you'll see it used like this:

{% for child in page.children %}
{% if child.type_name == 'Question' %}
<li><a href="{{ child.url }}">{{ child.headline }}</a></li>
{% endif %}
{% endfor %}

 

Hope this helps.

Thanks.

Share this post

Showing 1 reaction

How would you tag this suggestion?
Please check your e-mail for a link to activate your account.