Symfony 细枝加载器前置路径不工作

Symfony 细枝加载器前置路径不工作,symfony,twig,Symfony,Twig,在本教程之后,我尝试在symfony 2.5.6中使用主题: 所以我在声明为服务的TemplateListener中尝试了这个 $path = dirname(__DIR__) . '/Resources/themes/' . $theme . '/views'; $this->twig->getLoader()->prependPath($path, 'MyWebsiteFront'); 但这不起作用,未找到模板MyWebsiteFront:Index:Index.html

在本教程之后,我尝试在symfony 2.5.6中使用主题:

所以我在声明为服务的TemplateListener中尝试了这个

$path = dirname(__DIR__) . '/Resources/themes/' . $theme . '/views';
$this->twig->getLoader()->prependPath($path, 'MyWebsiteFront');
但这不起作用,未找到模板MyWebsiteFront:Index:Index.html.twig,但它存在于C:\www\MyWebsiteFront\src\MyWebsiteFront\Resources\themes\myteme\views\Index\Index.html.twig,该路径由$path生成

有什么想法吗?

根据,在渲染模板时,需要使用别名为该路径的名称空间引用模板,例如

@MyWebsiteFront/Index/index.html.twig
使用setpath、addPath和prependPath方法时, 未指定时,将命名空间指定为第二个参数, 这些方法作用于主命名空间:

$loader->addPath($templateDir, 'admin'); Namespaced templates can be
通过特殊的@namespace\u name/template\u路径表示法访问:

$twig->render('@admin/index.html', array());

注意:名称空间不是必需的。

您如何引用此模板?您是否使用$this->render'MyWebsiteFront::Index:Index.html.twig'数组从控制器加载它。。。或者您是在twig中使用它,与{%extends'MyWebsiteFront::Index:Index.html.twig“%”一起使用?