Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2, How to register an extension by using the `addExtension()` method on your main `Environment` object

Tags:

twig

symfony

I would like to load a new extension in a symfony2 project for twig but I don't know where should I put line below to work :

$twig = new Twig_Environment($loader, $config);
$twig->addExtension(new Twig_Extension_Debug());

Any tutorials for http://twig.sensiolabs.org/doc/functions/dump.html ?

like image 393
pmoubed Avatar asked Apr 24 '12 17:04

pmoubed


2 Answers

I could add debug for twig like below :

# app/config/config.yml
services:
    acme_hello.twig.extension.debug:
        class:        Twig_Extension_Debug
        tags:
             - { name: 'twig.extension' }

Look here for more details;

like image 107
pmoubed Avatar answered Nov 19 '22 17:11

pmoubed


You have to create a service with twig.extension tag. See here

like image 1
Mun Mun Das Avatar answered Nov 19 '22 16:11

Mun Mun Das