Add twig context for twig hook() function

Allows to use variables from template inside the hook file with usage of $context variable
This commit is contained in:
slawkens 2023-07-19 22:40:11 +02:00
parent 99c53c75f2
commit 9f67cab503

View File

@ -90,15 +90,16 @@ $function = new TwigFunction('truncate', function ($s, $n) {
}); });
$twig->addFunction($function); $twig->addFunction($function);
$function = new TwigFunction('hook', function ($hook, array $params = []) { $function = new TwigFunction('hook', function ($context, $hook, array $params = []) {
global $hooks; global $hooks;
if(is_string($hook)) { if(is_string($hook)) {
$hook = constant($hook); $hook = constant($hook);
} }
$params['context'] = $context;
$hooks->trigger($hook, $params); $hooks->trigger($hook, $params);
}); }, ['needs_context' => true]);
$twig->addFunction($function); $twig->addFunction($function);
$function = new TwigFunction('config', function ($key) { $function = new TwigFunction('config', function ($key) {