我在Twig模板上有这个代码:
{% if form_action is empty or form_action is null or form_action is not defined %}
{% set form_action = '' %}
{% endif %}
Run Code Online (Sandbox Code Playgroud)
但是当我加载页面时,我收到此错误消息:
第1行的AppBundle :: pdone.html.twig中不存在变量"form_action"
如何检查变量是否设置?条件不够吗?有什么建议?
您的陈述顺序不正确.通常这应该足够了:
{% if form_action is not defined %}
Run Code Online (Sandbox Code Playgroud)
看看a variable是否有值:
{% if form_action %}
Run Code Online (Sandbox Code Playgroud)