I have built a twig extension to do some things and one of them is render a template. How can I access from inside the twig extension the engine environment and call the Render method?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
@tvlooy answer give me a hint but didn't work for me. What I needed to to to achieve it is:
I needed addtionaly add
'is_safe' => ['html']
to avoid autoescaping of HTML.I've also registered the class as symfony service:
in TWIG template I've added
{{ myMenu() }}
I work with
"twig/twig": "~1.10"
and Symfony 3.1.3 versionYou can define the extension so that it needs the environment. Twig will automatically pass it to the function.
For older versions of Twig
Using this function the user can pass the twig environment instance to a twig extension