Tutorial by Examples

Here are some example on how to add new filters/functions to twig,the synax for adding Twig_Functions are the same as the Twig_Filter ones, just change the keywords accordingly <?php $twig = new Twig_Environment($loader); /* You can chain a global function */ $twig->addFilter(ne...
You can group all your custom functions/filters/tests/... inside a custom Twig_Extension class: ProjectTwigExtension class ProjectTwigExtension extends Twig_Extension { public function getFunctions() { return array( new Twig_SimpleFunction('twig_function_name', array($...
How to ... 1 - use twig extension class that extends use \Twig_Extension class dobToAge extends \Twig_Extension { 2 - Add the appropriate filter by overriding getFilters() method public function getFilters() { return array( 'age' => new \Twig_Filter_Method($this, '...

Page 1 of 1