Html 如何在给定用例的twig中使用IF语句

Html 如何在给定用例的twig中使用IF语句,html,if-statement,twig,Html,If Statement,Twig,我用树枝做模板 {{ content.field_votre_type_the_profil[0] }} returns "test string" 所以当我在if语句中比较它时,它不起作用。。。 比如说 {% if content.field_votre_type_the_profil[0] == "test string" %} <p>Hey i found the string</p> {% endif %} {%if content.field\u v

我用树枝做模板

{{ content.field_votre_type_the_profil[0] }} returns "test string"
所以当我在if语句中比较它时,它不起作用。。。 比如说

{% if content.field_votre_type_the_profil[0] == "test string" %}
    <p>Hey i found the string</p>
{% endif %}
{%if content.field\u votre\u type\u profile[0]==“test string”%}
嘿,我找到绳子了

{%endif%}
我没有得到输出中的“嘿,我找到了字符串”


有什么想法吗?

试着颠倒逻辑,然后说:

{% if content.field_votre_type_the_profil[0] != "test string" %}
如果您的p标签出现,则表示您的值在某处丢失/覆盖

如果你不能让它打印你的html,不管你的逻辑是什么:检查你的语法是否正确,确保插件本身没有发生错误,等等

如果您尝试过其他方法,请告诉我,我会提供更多帮助

试试这个,告诉我它打印了什么:

{% if content.field_votre_type_the_profil[0] == "test string" %}
    <p>Hey i found the string</p>
{% else %}
    <h1>Your variable is being overwritten, or not included for some reason</h1>
{% endif %}

{{ content.field_votre_type_the_profil[0] }}
{%if content.field\u votre\u type\u profile[0]==“test string”%}
嘿,我找到绳子了

{%else%} 由于某种原因,您的变量正在被覆盖或未包含 {%endif%} {{content.field_votre_type_the_profile[0]}
我能解决这个问题

我必须更深一层来做这个计算

{% if content.field_votre_type_the_profil[0]['#markup'] ==  "test string" %}

我已经尝试了反转逻辑…当我这样做时,我会得到类似于Twig\u error\u语法的错误:意外字符“!”。我也试着用单引号代替双引号……但仍然不起作用……我的“p”标记根本没有打印……并且没有出现错误。我得到“您的变量正在被覆盖,或者由于某种原因未包含”