在我需要使用此模板的每个模板中
{{ form_stylesheet(form) }}
{{ form_javascript(form) }}
如果页面没有加载任何表单变量,即其普通页面,则模板会给出错误。
有什么方法可以检查form
是否存在然后加载它们,否则不会
if (form.present) then
{{ form_stylesheet(form) }}
{{ form_javascript(form) }}
{% if form is defined %}
{{ form_stylesheet(form) }}
{{ form_javascript(form) }}
{% endif %}
http://twig.sensiolabs.org/doc/tags/if.html