【问题标题】:Impossible to access an attribute Error无法访问属性错误
【发布时间】:2013-06-03 22:23:48
【问题描述】:

我从 twig 开始,我有一个小问题。我不知道如何解决它。我想检查变量是否不为空来设置标题页。我也试过“不为空”。

{% if item is not empty %}
    {% block title "Item " ~ item.name %}
{% endif %}

当有一个 Item 对象时它可以工作,但是当它为 null 时它不起作用。为什么它不起作用?我收到此错误

Impossible to access an attribute ("name") on a NULL variable ("")

【问题讨论】:

    标签: twig


    【解决方案1】:

    试试

    {% if item is not defined %}
    {% block title "Item " ~ item.name %}
    {% endif %}
    

    改为。

    如果需要,look at the documentation

    【讨论】:

      猜你喜欢
      • 2013-03-20
      • 1970-01-01
      • 2013-02-01
      • 2012-12-28
      • 2015-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多