[Question] How to get Template Name using a TwigFunction #3790
-
I am in the process of upgrading Twig from v1 to v3. I had a SimpleFunction for debug purposes and one of the things the function showed was the name of the template, For Twig 1, the code looked like this:
For Twig 3, the code looks like this:
I had to comment the 4th parameter because it breaks the execution of the script. TIA |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I am really struggling with it because I want to implement this feature but I am not that good with complex OOP. What I can do from within my above function is to access the When I print_r this object I get the content of the entire object.
and
particularly "lineo" where "value" = debug_dump Can anyone please help me to access these from the object? |
Beta Was this translation helpful? Give feedback.
-
I know I'm late, but isn't it as simple as declaring that your function requires the template to be passed as argument to it? $oTwig->addFunction(new \Twig\TwigFunction("debug_dump",
function ($template, $mVar = '', $sCaption = '', $bVarDump = false) use ($oTwig) {
return debug_dump($mVar, $sCaption, $bVarDump, $template->getTemplateName());
}
), [
'needs_template' => true
]); |
Beta Was this translation helpful? Give feedback.
I am really struggling with it because I want to implement this feature but I am not that good with complex OOP.
What I can do from within my above function is to access the
Twig\Environment Object
When I print_r this object I get the content of the entire object.
What I would like to access directly are the following things:
and