gpt4 book ai didi

symfony - Twig dump 不打印任何内容

转载 作者:行者123 更新时间:2023-12-02 16:27:38 26 4
gpt4 key购买 nike

我现在有点困惑。我总是像其他 Twig 函数一样使用 Twig 转储函数,但现在它完全没有输出。没有错误/异常,什么都没有。其他一切都工作正常,例如反式过滤器。

{{ 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 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 开发工具栏中,以避免搞乱页面布局。

In 2.6.0, this will be fixed by having a fallback to the native twig dump() function why the DebugBundle is not registered.

关于symfony - Twig dump 不打印任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26915293/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com