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...