mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 17:29:21 +02:00
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:
parent
99c53c75f2
commit
9f67cab503
@ -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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user