Do you sometimes wish you could just do a var_dump inside a Twig template while trying to debug some code? Well Twig comes with its own Debug extension to allow you to do just that.
Firstly, add the following to your /app/config/config_dev.yml (you don’t want to do this on Prod):
twig:
debug: 1
services:
debug.twig.extension:
class: Twig_Extensions_Extension_Debug
tags: [{ name: 'twig.extension' }]
Now inside your Twig templates you can “var_dump” variables using the built-in Twig Debug:
{% debug nameOfVariable %}
Happy debugging!
Twig: How to var_dump variables inside a template – dividebyzero
More than 3 requests, I'll translate this to Chinese.
超过3个请求,我就会把这篇文章翻译成中文。
No comments:
Post a Comment