skip to Main Content

I have a problem with a if else statement.
I have a collection which sort by 2 different tags: material and size.
I want an heading and paragraph to show, when neither a material or material and size is chosen.
You can see the collection here: https://www.sengefabriksudsalg.dk/collections/madrasser/

I have tried this:

{% if pageValues contains 'Latexmadrasser' %}
<h2 class="mat-h2-collecion">Latexmadrasser</h2>
<p> Hello </p>

{% elsif pageValues contains 'Latexmadrasser' and '70x200'  %}
<h2 class="mat-h2-collecion">Latexmadrasser 70x200</h2>
<p> Hello </p>

{% endif %}

But it prints only the first statement 🙁

2

Answers


  1. Re-order your clauses from most to least specific. Your second clause would only ever be evaluated if pageValue does not include ‘Latexmadrasser’, since this condition would already be enough to satisfy the first if, so you’ll never reach the elif.

    {% if pageValues contains 'Latexmadrasser' and pageValues contains '70x200' %}
    <h2 class="mat-h2-collecion">Latexmadrasser 70x200</h2>
    <p> Hello </p>
    
    {% elsif pageValues contains 'Latexmadrasser' %}
    <h2 class="mat-h2-collecion">Latexmadrasser</h2>
    <p> Hello </p>
    
    {% endif %}
    
    Login or Signup to reply.
  2. shouldn’t this be:

    if pageValues contains 'Latexmadrasser' and pageValues contains '70x200'
    

    my liquid is not up to date though.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search