Twig模板的Not子句

问题描述:

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 %}

如何在类似于PHP的! code>的Twig模板中执行NOT子句? 给定 true code>或 false code>的 sick code>值,我尝试了以下操作,但它会抛出错误。 p> {%if!sick%} Kenny没病。 {%elseif dead%} 你杀了肯尼! 你这个混蛋!!! {%else%} 肯尼看起来没问题---到目前为止 {%endif%} code> pre> div>

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.