You are here

function hook_twig_tweak_functions_alter in Twig Tweak 3.1.x

Same name and namespace in other branches
  1. 3.x twig_tweak.api.php \hook_twig_tweak_functions_alter()

Alters Twig Tweak functions.

Parameters

\Twig\TwigFunction[] $functions: Twig functions to alter.

1 function implements hook_twig_tweak_functions_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

twig_tweak_test_twig_tweak_functions_alter in tests/twig_tweak_test/twig_tweak_test.module
Implements hook_twig_tweak_functions_alter().
1 invocation of hook_twig_tweak_functions_alter()
TwigTweakExtension::getFunctions in src/TwigTweakExtension.php

File

./twig_tweak.api.php, line 24
Hooks specific to the Twig Tweak module.

Code

function hook_twig_tweak_functions_alter(array &$functions) : void {

  // A simple way to implement lazy loaded global variables.
  $functions[] = new TwigFunction('var', function (string $name) {
    $value = NULL;
    switch ($name) {
      case 'foo':
        $value = 'Foo';
        break;
      case 'bar':
        $value = 'Bar';
        break;
    }
    return $value;
  });
}