File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * @param Twig_Environment $env - The Twig Environment - https://twig.symfony.com/api/1.x/Twig_Environment.html
5+ * @param $config - Config of `@basalt/twig-renderer`
6+ */
7+ function addCustomExtension (\Twig_Environment &$ env , $ config ) {
8+
9+ /**
10+ * @example `<h1>Hello {{ customTwigFunctionThatSaysWorld() }}!</h1>` => `<h1>Hello Custom World</h1>`
11+ */
12+ // $env->addFunction(new \Twig_SimpleFunction('customTwigFunctionThatSaysWorld', function () {
13+ // return 'Custom World';
14+ // }));
15+
16+ /*
17+ * Reverse a string
18+ * @param string $theString
19+ * @example `<p>{{ reverse('abc') }}</p>` => `<p>cba</p>`
20+ */
21+ // $env->addFunction(new \Twig_SimpleFunction('reverse', function ($theString) {
22+ // return strrev($theString);
23+ // }));
24+
25+
26+ // $env->addExtension(new \My\CustomExtension());
27+
28+ // `{{ foo }}` => `bar`
29+ // $env->addGlobal('foo', 'bar');
30+ }
Original file line number Diff line number Diff line change 4444 " source/_macros"
4545 ]
4646 }
47- ]
47+ ],
48+ "alterTwigEnv" : [{
49+ "file" : " alter-twig.php" ,
50+ "functions" : [" addCustomExtension" ]
51+ }]
4852 }
4953 },
5054 "cacheBust" : true ,
You can’t perform that action at this time.
0 commit comments