Skip to main content

I am trying to show or hide content based on event variables.

If I want to show “This works” when the ids are 11111 or 22222, the if condition works.

{% if event.id = '11111' or event.id = '22222' %}
This works.
{% endif %}

 

If I want to hide “Does not work” when the ids are 11111 or 22222, the if condition with the != does not work.

{% if event.id != '11111' or event.id != '22222' %}
Does not work.
{% endif %}

 

Any ideas why not, or is the syntax incorrect?

 

(I’m not looking for a work around at this stage, like show/hide blocks based on those variables, but am trying to solve it inline)

Hi there @gmc

 

Thanks for sharing your question with us! 

 

Yes, the syntax you use in your if/etc statements is very important to whether or not they’re successful. We just had an amazing Klaviyo employee @Anna McCarthy share out all her template wisdom in a series and I’d recommend checking out this specific topic in her series addressing these statements. I think they will clear up the confusion for you and give you more insight into this feature as our current help center documentation doesn’t go into as much detail! 

 

Thanks for participating in the Community!

-Taylor


Thanks for the reply, but it wasn’t quite what I was after. I was looking to display a block of text if a condition was not true, using “!=” (not equal).

Less elegant workaround was to leave the if = blank, and the have it display in the else.

{% if event.id = '11111' or event.id = '22222' %}
{% else %}
This works.
{% endif %}


Reply