Symfony 访问if语句中的form.vars.value(细枝)

Symfony 访问if语句中的form.vars.value(细枝),symfony,if-statement,twig,Symfony,If Statement,Twig,我尝试在twig中选择表单字段值,以便在元素处于活动或停用状态时显示红色/绿色状态 但它不起作用,我总是得到一个 Impossible to access an attribute ("enabled") on a NULL variable ("") 这是我的代码,我不确定是否缺少大括号或类似的东西 {% if form.vars.value.enabled is null %} <h2 class="device-off"> {% else %}

我尝试在twig中选择表单字段值,以便在元素处于活动或停用状态时显示红色/绿色状态

但它不起作用,我总是得到一个

Impossible to access an attribute ("enabled") on a NULL variable ("")
这是我的代码,我不确定是否缺少大括号或类似的东西

{% if form.vars.value.enabled is null %}
        <h2 class="device-off">
    {% else %}
        <h2 class="device-on">
    {% endif %}
{%if form.vars.value.enabled为null%}
{%else%}
{%endif%}

使用dump查看form.vars变量

{{ dump(form.vars) }}

上述解决方案有效。。。如果对db请求使用正确的参数;(我在使用dump{{dump(form.vars.value.enabled)}时找到了它)