@Wanze @Gazley I can´t get it running. I even tried to write a module but I don´t know which class to extend.
Gazley could you send me your module as a reference? Here is the code of my module:
<?php
class TwigFunctions{
public static function getModuleInfo() {
return array(
'title' => "TwigFunctions",
'version' => "0.0.1",
'summary' => "",
'author' => "Sir Aceman",
'href' => "",
'permission' => array("page-view"),
'autoload' => true,
'singular' => true,
'permanent' => false,
'requires' => array("PHP>=5.4.0", "ProcessWire>=2.5.28", ""),
);
}
public function init() {
$this->addHookAfter('TemplateEngineTwig::initTwig', $this, 'hookInitTwig');
}
function hookInitTwig(HookEvent $event)
{
$twig = $event->arguments('twig');
$twigWireRelativeTimeStr = new Twig_SimpleFunction('wireRelativeTimeStr', function ($date) {
return wireRelativeTimeStr($date);
});
$twig->addFunction($twigWireRelativeTimeStr);
$function = new Twig_SimpleFunction('testfunction', function ($string) {
return 'testfunction';
});
$twig->addFunction($function);
}
}