let\'s say I have created a custom twig function: templateName.
$twig = new Twig_Environment($loader);
$twig->addFunction(\'templateName\', new Twig_Func
For everyone who needs an answer to the initial question, I found a solution that twig itself is using in the Twig_Error class.
protected function guessTemplateInfo()
{
$template = null;
foreach (debug_backtrace() as $trace) {
if (isset($trace['object']) && $trace['object'] instanceof Twig_Template && 'Twig_Template' !== get_class($trace['object'])) {
$template = $trace['object'];
}
}
// update template filename
if (null !== $template && null === $this->filename) {
$this->filename = $template->getTemplateName();
}
/* ... */
best regards!