如何在树枝模板中 var_dump 变量? [英] How to var_dump variables in twig templates?

查看:26
本文介绍了如何在树枝模板中 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 类型错误.添加twig函数的php代码应该放在哪里?

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 开始,正确的答案是使用转储函数.Twig 文档中有完整的文档.这是在 Symfony2 中启用此功能的文档.

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) }}

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆