Using this manual, I added dynamic field to my form. Now, how can I check existence of this field in my template?
使用本手册,我在表单中添加了动态字段。现在,我如何在模板中检查此字段的存在?
{{ form_start(form) }}
{{ form_errors(form) }}
{% if ??? %} <---------------------------
{{ form_row(form.myDynamicField) }}
{% endif %}
{{ form_end(form) }}
3 个解决方案
#1
17
What about,
关于什么,
{% if form.myDynamicField is defined %}
{{ form_row(form.myDynamicField) }}
{% endif %}
You may also need to check if form.myDynamicField
is not null.
您可能还需要检查form.myDynamicField是否为null。
#2
4
I know this question is a few years old, but you could also make it a shorter ternary operator.
我知道这个问题已经有几年了,但你也可以把它变成一个更短的三元运算符。
{{ form.myDynamicField is defined ? form_row(form.myDynamicField) : null }}
{{form.myDynamicField是否已定义? form_row(form.myDynamicField):null}}
#3
1
{{ form_start(form) }}
{{ form_errors(form) }}
{% if form.getChildren['myDynamicField'] is defined %}
{{ form_row(form.myDynamicField) }}
{% endif %}
{{ form_end(form) }}
#1
17
What about,
关于什么,
{% if form.myDynamicField is defined %}
{{ form_row(form.myDynamicField) }}
{% endif %}
You may also need to check if form.myDynamicField
is not null.
您可能还需要检查form.myDynamicField是否为null。
#2
4
I know this question is a few years old, but you could also make it a shorter ternary operator.
我知道这个问题已经有几年了,但你也可以把它变成一个更短的三元运算符。
{{ form.myDynamicField is defined ? form_row(form.myDynamicField) : null }}
{{form.myDynamicField是否已定义? form_row(form.myDynamicField):null}}
#3
1
{{ form_start(form) }}
{{ form_errors(form) }}
{% if form.getChildren['myDynamicField'] is defined %}
{{ form_row(form.myDynamicField) }}
{% endif %}
{{ form_end(form) }}