Would it be possible to add functions to Twig within the theme PHP file (IE: antimatter.php)?
Themes & Styling
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 | 251 | 2 weeks ago | ||
| 5 | 317 | 3 weeks ago | ||
| 1 | 310 | 4 weeks ago | ||
| 1 | 348 | 1 month ago | ||
| 4 | 474 | 2 months ago |