从 Twig 模板名称解析本地文件路径 [英] Resolve local file path from Twig template name
本文介绍了从 Twig 模板名称解析本地文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
转换此字符串的程序化步骤是什么:
What are the programmatic steps to turn this string:
AcmeProjectBundle::home.html.twig
进入这个?
/path/Symfony/src/Acme/ProjectBundle/Resources/views/home.html.twig
推荐答案
如果你想从控制器中检索路径,你可以使用以下代码:
If you want to retrieve path from a controller you can use this code:
$parser = $this->container->get('templating.name_parser');
$locator = $this->container->get('templating.locator');
$path = $locator->locate($parser->parse('AcmeProjectBundle::home.html.twig'));
有关更多信息,请查看以下代码:
For more info take a look at code of:
Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser::parse
Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator::locate
这篇关于从 Twig 模板名称解析本地文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文