本文介绍了如何在twig模板中var_dump变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看图层模式,只显示您所给予的内容是否正常,但您如何知道可用的内容?在TWIG中是否有列出所有定义的变量功能?有一种方法来转储变量?

View layer pattern where you only present what you have been given is fine and all, but how do you know what is available? Is there a "list all defined variables" functionality in TWIG? Is there a way to dump a variable?

我通过搜索找到的解决方案是定义一个函数,我可以使用我的现有的php调试工具通过,但是我发现的所有引用包括这两行很好的代码,但是它没有指定放置它们的位置。根据他们需要一个 $ loader 变量定义的事实,我尝试过/app/config/autoload.php,但$ loader是错误的。

The solution I found by searching for it was to define a function where I can use my existing php debug tools by injecting a function, but all references I have found to that includes these nice two lines of code, but nowhere is it specified where to place them. Going by the fact that they need a $loader variable defined, I tried /app/config/autoload.php but the $loader there was the wrong kind. Where do I place the php code for adding a twig function?

推荐答案

从Twig 1.5开始,正确的答案是使用转储功能。 。

As of Twig 1.5, the correct answer is to use the dump function. It is fully documented in the Twig documentation. Here is the documentation to enable this inside Symfony2.

{{ dump(user) }}

这篇关于如何在twig模板中var_dump变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 07:31