我添加模板(index.html.twig)簡單地說:如何在TWIG中使用轉儲?
{{ dump(product) }}
,我有錯誤:
The function "dump" does not exist in AcmeStoreBundle:Default:index.html.twig at line 2
爲什麼此功能未啓用,以及我怎樣才能使這個?
我添加模板(index.html.twig)簡單地說:如何在TWIG中使用轉儲?
{{ dump(product) }}
,我有錯誤:
The function "dump" does not exist in AcmeStoreBundle:Default:index.html.twig at line 2
爲什麼此功能未啓用,以及我怎樣才能使這個?
您需要to configure調試擴展:
# app/config/config.yml
services:
acme_hello.twig.extension.debug:
class: Twig_Extension_Debug
tags:
- { name: 'twig.extension' }
每上述鏈接,嫩枝調試設置默認情況下,Symfony的2.5+運行嫩枝1.16+工作,和定製服務的定義是沒有必要的。 See this answer for more details。
我不知道這些是舊的答案或只是不完整,但這絕對不適合我。我已經嘗試了這個答案的許多不同版本,無濟於事。 – 2014-10-01 00:24:38
@ChadwickMeyer有一個鏈接,說你需要的是在配置中啓用它'twig:debug:true' – meze 2014-10-01 17:12:06
謝謝。我已經這樣做了,但沒有奏效。但我也從Symfony 2.4升級到2.5並且運行'composer update'(它從Twig 1.15升級到了1.16,現在它工作了,所以誰知道...... – 2014-10-01 21:57:10
Symfony的2.7+ UPDATE:
的DebugBundle允許組件進入的Symfony堆滿框架的更高的集成。它在Symfony標準版的開發和測試環境中默認啓用。
檢查VarDumper component及其integration on Twig。
OLD答:
我想提出一個非本地解決方案。你需要一個第三方軟件包,但最終的結果會很棒!
改進了dump
版本:
ldd()
,這是一個別名內存問題爲經典的「傾倒和死亡」php app/console ladybug:dump "Symfony\Component\HttpFoundation\Request"
)下面的鏈接:
在symfony中不起作用3 – mehmetsen80 2016-12-06 17:16:31
關於Symfony 2.7+你最好用官方的'VarDumper'組件:http://symfony.com/doc/current/components/var_dumper.html#debugbundle-and-twig-integration – 2016-12-06 17:23:56
當您配置它像@meze說,你可以顯示所有自定義變量:
<h1>Variables passed to the view:</h1>
{% for key, value in _context %}
{% if key starts with '_' %}
{% else %}
<pre style="background: #eee">{{ key }}</pre>
{{ dump(value) }}
{% endif %}
{% endfor %}
你可以用我簡單的插件,以方便檢查你的變量:的
可能重複[如何var_dump在樹枝模板變量?](http://stackoverflow.com/questions/7317438/how-to-var-dump-variables-in-twig-templates) – meze 2012-04-12 08:54:16