Twig dump不打印任何东西

时间:2014-11-13 17:55:10

标签: symfony twig twig-extension symfony-2.6

我现在有点困惑。我总是使用twig dump函数像任何其他twig函数,但现在它绝对没有输出。没有错误/异常,只是没有。 其他一切都很好,就像反式过滤器一样。

{{ dump('test') }} # prints nothing
{{ 'layout.booking.chooseArea'|trans }} # prints the translated message

现在这个模板不包含任何其他内容。 转储在父模板或base.html.twig中也不起作用。

同样,转储什么都不打印:不是空字符串,不是空,而不是屏幕上的单个像素。

任何可能导致此问题的想法?

Symfony版本:2.6.x-dev

更新

{{ dump('test') }} # doesn't work (anymore?)
{% dump('test') %} # does (still) work

这已经删除了吗?为什么没有错误?顺便说一下......设置了调试标志。

1 个答案:

答案 0 :(得分:5)

在Symfony 2.6中,有一个新的VarDumper组件和DebugBundle。这些覆盖了twig的dump()函数,可以提供更多更好的转储输出。

但是,您必须在AppKernel中注册DebugBundle,否则它将忽略该调用。为此,您应将其添加到app/AppKernel.php

// app/AppKernel.php

// ...
public function registerBundles()
{
    // ...

    if (in_array($this->getEnvironment(), array('dev', 'test'))) {
        $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
        // ...
    }

    return $bundles;
}

请注意,这个新的转储功能会将输出转储到web开发工具栏中,以避免搞砸页面布局。

  

在2.6.0中,这将通过回退本机twig dump()函数来修复,为什么DebugBundle没有注册。

相关问题