Multiple or clauses not working

Hi all,

It’s a noob question but can’t seam to manage it. We have this code in one clients website:
{% for destinatie in destinatii %}
{% if (this.page.id == ‘ce-sa-vezi’ and destinatie.category == ‘1’ or destinatie.category == ‘2’ or destinatie.category == ‘3’ or destinatie.category == ‘4’ or destinatie.category == ‘5’ or destinatie.category == ‘6’ or destinatie.category == ‘7’ or destinatie.category == ‘8’) %}
{% partial ‘cards/destinatie’ %} Toate
{% elseif this.page.id == ‘ce-sa-vezi-rezervatii’ and destinatie.category == ‘1’ %}
{% partial ‘cards/destinatie’ %}
{% elseif this.page.id == ‘ce-sa-vezi-natura’ and destinatie.category == ‘2’ %}
{% partial ‘cards/destinatie’ %}
{% elseif this.page.id == ‘ce-sa-vezi-monumente’ and destinatie.category == ‘3’ %}
{% partial ‘cards/destinatie’ %} Monumete
{% elseif this.page.id == ‘ce-sa-vezi-edificii-religioase’ and destinatie.category == ‘4’ %}
{% partial ‘cards/destinatie’ %}
{% elseif this.page.id == ‘ce-sa-vezi-mestesuguri’ and destinatie.category == ‘5’ %}
{% partial ‘cards/destinatie’ %}
{% elseif this.page.id == ‘ce-sa-vezi-muzee’ and destinatie.category == ‘6’ %}
{% partial ‘cards/destinatie’ %}
{% elseif this.page.id == ‘ce-sa-vezi-patrimoniu-minier’ and destinatie.category == ‘7’ %}
{% partial ‘cards/destinatie’ %}
{% elseif this.page.id == ‘ce-sa-vezi-altele’ and destinatie.category == ‘8’ %}
{% partial ‘cards/destinatie’ %}
{% endif %}
{% endfor %}

The result shoul be that for the first query it should show all the entryes and for the elseif’s it should show only the page + specific one category. The problem is that for all the querys the result is ALL. If we delete the long “or” clauses, the single entryes with specific page are showing.

Thank you in advance.

you are always displaying this partial in every case. Im not sure what is the question then and the roles of all this if and or which can be refactored in a much more readable and maintainable way;

Hi there - you have an error in your if clause, just a misplaced bracket.

You got: if( pageId and category1 or aSetOfCategories )
→ match if the page is ‘ce-sa-vezi’ and category 1 OR a set of categories

But you want: if ( pageId and aSetOfCategories )
→ match if the page is ‘ce-sa-vezi’ and a set of categories

{% if this.page.id == ‘ce-sa-vezi’ and **(**destinatie.category == ‘1’ or destinatie.category == ‘2’ or destinatie.category == ‘3’ or destinatie.category == ‘4’ or destinatie.category == ‘5’ or destinatie.category == ‘6’ or destinatie.category == ‘7’ or destinatie.category == ‘8’) %}
{% partial ‘cards/destinatie’ %} Toate
{% elseif this.page.id == ‘ce-sa-vezi-rezervatii’ and destinatie.category == ‘1’ %}

And you should refactor that to something like

{% if (this.page.id == ‘ce-sa-vezi’ and destinatie.category in [‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’] %}

or maybe even create variables with the fixes values (page slug <> category mapping).

Thank you very much for your great answer. The solution with grouped set of categoryes did the job.


{% if (this.page.id == ‘ce-sa-vezi’ and destinatie.category in [‘1’,‘2’,‘3’,‘4’,‘5’’,‘6’,‘7’,‘8’]) %}

All the best.