0

How do I do a NOT clause in a Twig template similar to PHP's !? Given sick values of either true or false, I tried the following, but it throws an error.

{% if !sick %}
    Kenny is NOT sick.
{% elseif dead %}
    You killed Kenny! You bastard!!!
{% else %}
    Kenny looks okay --- so far
{% endif %}
user1032531
  • 24,767
  • 68
  • 217
  • 387
  • "if not var"? Out on the run so couldnt check atm, strange if its not mentioned in the docs – JimL Sep 22 '14 at 16:14
  • @JimL I was looking in the IF section http://twig.sensiolabs.org/doc/tags/if.html. Turned out to be located elsewhere. – user1032531 Sep 22 '14 at 16:26

1 Answers1

1

You should use not keyword as negation.

{% if not sick %}
    Kenny is NOT sick.
{% elseif dead %}
    You killed Kenny! You bastard!!!
{% else %}
    Kenny looks okay --- so far
{% endif %}

Following this documentation page and this answear.

Community
  • 1
  • 1
marian0
  • 3,336
  • 3
  • 27
  • 37