繁体   English   中英

如何检查symfony2中twig模板中是否存在某个变量

[英]How to check if some variable is present in twig template in symfony2

在每个模板中我都需要使用这个步骤

{{ 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM