找不到模板bundle:默认值:index.html.twig



我在运行Symfony时遇到一些问题。事实上,它找不到默认的树枝模板。我根本没有接触代码,只是生成了我的捆绑包,并试图访问/web/app_dev.php.

我的模板在中

/src/OC/PlatformBundle/Resources/views/Default/index.html.twig.

Symfony查看了这些位置,但没有查看我的模板实际所在的位置。

/app/Resources/views
/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form

DefaultController.php indexAction()看起来不错:

public function indexAction(){
return $this->render("OCPlatform:Default:index.html.twig");
}

如果你们中的任何人曾经面临过这种问题,或者知道问题来自哪里,我提前感谢你们的帮助。

Arthur

我遇到了同样的问题,我用以下途径解决了它:

public function indexAction(){
return $this->render("@OCPlatform/Default/index.html.twig");
}

用"/"编辑":"就可以了。也许可以帮助其他开发人员

如果您想继续使用'OCPlatform:Default:index.html.titch'格式的模板,请编辑您的app/config/config.yml文件:

#app/config/config.yml框架:模板:engines:['twig']

这解决了我的问题。您可以查看此链接Symfony 3.4在我的捆绑包中使用视图

根据文档(Symfony>=3.4),您应该在控制器中写入模板的路径,如下所示:

public function indexAction(){
return $this->render("@OCPlatform:Default:index.html.twig");
}

这对我很有效:

return $this->render('@HomeBundle/Default/index.html.twig');


希望:)

引用捆绑包中的模板¶

如果您需要引用捆绑包中的模板,Symfony会使用
Twig命名空间语法(@BundleName/directory/filename.html.twitch)。
这允许多种类型的模板,每种模板都位于特定位置:

@AcmeBlog/Blog/index.html.twig: <br>This syntax is used to specify a template for a specific page. The three parts of the string, each separated by a slash (/), mean the following:<br>
@AcmeBlog: is the bundle name without the Bundle suffix. This template lives in the AcmeBlogBundle (e.g. src/Acme/BlogBundle);<br>
Blog: (directory) indicates that the template lives inside the Blog subdirectory of Resources/views/;<br>
index.html.twig: (filename) the actual name of the file is index.html.twig.

在symfony 4中使用此:

return $this->render("@Platform/Default/index.html.twig");

最新更新