Lukas
Lukas

Reputation: 7734

If is not variable Twig condition

I need to set some conditions in twig, so i have this:

{% if app.session.get('campaignVersion') is not null and is not '4.4d'}
...
{% elseif app.session.get('campaignVersion') is null or '4.4d' %}
...
{% endif %} 

But i have errors with syntax and logic, maybe it must have an standard operator such as !=, what i'm doing wrong? Thx for help.

Upvotes: 2

Views: 3960

Answers (2)

Alain
Alain

Reputation: 36984

Twig is not a human language interpreter :-)

Twig is not able to implicitly know who is the subject in and is not '4.4d'.

Try with:

{% if app.session.get('campaignVersion') is not null and app.session.get('campaignVersion') != '4.4d' %}

Or for better readibility:

{% if app.session.get('campaignVersion') not in [null, '4.4d'] %}

Upvotes: 6

Ryokel
Ryokel

Reputation: 80

A % is missing at the end of the first line

Upvotes: 0

Related Questions