RSS Feed

Search...

Tag Archive:   twig


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!

Sometimes you don’t want to render all of the elements of a form using form_rest but you’re still required to render the hidden CSRF Token on a Symfony2 form.

To render only the CSRF Token, use the following:

 {{ form_row(form._token) }} 
Use the following code to check if a variable exists within a Twig template:
 {% if theVariable is defined %}