Would it be possible to add functions to Twig within the theme PHP file (IE: antimatter.php)?
Yes! In the class named after the theme inside a method onTwigExtensions, you can add something like:
PHP
// ...
public function onTwigExtensions()
{
$function = new \Twig_SimpleFunction ('mytest', function () {
return "This is a test.";
});
$this->grav['twig']->twig->addFunction($function);
}
// ...
And use it in Twig with {{ mytest() }}.
@punchfighter in addition to @Utis comment read this (extend twig)
Log in to reply.
Suggested topics
| Topic | Participants | Replies | Views | Activity |
|---|---|---|---|---|
| 3 | 193 | 2 weeks ago | ||
| 0 | 111 | 2 weeks ago | ||
| 1 | 206 | 3 weeks ago | ||
| 1 | 324 | 3 weeks ago | ||
| 6 | 1523 | 3 weeks ago |