-
Notifications
You must be signed in to change notification settings - Fork 1
/
alter-twig.php
34 lines (26 loc) · 1.05 KB
/
alter-twig.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
/**
* @param Twig_Environment $env - The Twig Environment - https://twig.symfony.com/api/1.x/Twig_Environment.html
* @param $config - Config of `@basalt/twig-renderer`
*/
function addCustomExtension(\Twig_Environment &$env, $config) {
/**
* @example `<h1>Hello {{ customTwigFunctionThatSaysWorld() }}!</h1>` => `<h1>Hello Custom World</h1>`
*/
// $env->addFunction(new \Twig_SimpleFunction('customTwigFunctionThatSaysWorld', function () {
// return 'Custom World';
// }));
/*
* Reverse a string
* @param string $theString
* @example `<p>{{ reverse('abc') }}</p>` => `<p>cba</p>`
*/
// $env->addFunction(new \Twig_SimpleFunction('reverse', function ($theString) {
// return strrev($theString);
// }));
// $env->addExtension(new \My\CustomExtension());
// `{{ foo }}` => `bar`
// $env->addGlobal('foo', 'bar');
// example of enabling the Twig debug mode extension (ex. {{ dump(my_variable) }} to check out the template's available data) -- comment out to disable
// $env->addExtension(new \Twig_Extension_Debug());
}