 <p>You can do it. There are two main parts in the workflow of any programming language or scripting language workflow, lexing and compiling. In the compiling part, the Twig builds the token tree and then compiles it into a HTML (<a href="http://twig.sensiolabs.org/doc/internals.html" rel="nofollow">Twig internals</a>).</p> <p>All of that is called inside Twig_Environment class, which is used as a service inside Symfony. So what you could do is override the <code>Twig_Environment tokenize</code> method and get all the tokens you need there. You can then <a href="http://symfony.com/doc/current/cookbook/bundles/override.html" rel="nofollow">override the original service</a> with your own modified extension. </p> <p>This is how you would be able to return all the token names. You can adapt this to suit your needs. You can also override <code>render</code> and/or <code>parse</code> methods if you need the token tree itself, or you can write your own more complex additional functionality which you could call from the template itself. The possibilities are endless. Just mind to keep your code separate from the original Twig implementation (use overrides) so that you can update more easily.</p>