【问题标题】:Twig dump isn't printing anything树枝转储没有打印任何东西
【发布时间】:2014-11-13 17:55:09
【问题描述】:

我现在有点困惑。我总是像使用任何其他 twig 函数一样使用 twig dump 函数,但现在它绝对没有输出。没有错误/异常,什么都没有。 其他一切正常,例如 trans 过滤器。

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

目前,此模板不包含任何其他内容。 转储在父模板或 base.html.twig 中也不起作用。

再次,转储不打印任何内容:不是空字符串,不是 null,也不是屏幕上的单个像素。

有什么可能导致这种情况的想法吗?

Symfony 版本:2.6.x-dev

更新

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

这是被删除还是什么?为什么没有错误?顺便说一句...调试标志已设置。

【问题讨论】:

    标签: symfony twig twig-extension symfony-2.6


    【解决方案1】:

    在 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 未注册。

    【讨论】:

    • 谢谢,有趣的信息。但是我在调​​试工具栏中没有看到它,但仍然在内容中。这个有特殊的配置值吗?
    • 好吧,我不知道我做了什么(实际上什么都没有),但现在它突然出现在工具栏中......我已经喜欢它了! :)
    猜你喜欢
    • 1970-01-01
    • 2020-01-10
    • 1970-01-01
    • 2016-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多