无法找到模板Bundle:默认值:index.html.twig

时间:2017-12-21 22:18:46

标签: symfony

我在运行Symfony时遇到了一些麻烦。实际上,它无法找到默认的树枝模板。我根本没有触摸代码,juste生成了我的包并尝试访问/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");
}

如果你们中的任何人遇到过这类问题,或者想知道问题出在哪里,我会事先感谢你的帮助。

亚瑟

6 个答案:

答案 0 :(得分:1)

我遇到同样的问题,我用这条路线解决了这个问题:

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

使用“/”编辑“:”并且它可以正常工作。 也许可以帮助其他开发者

答案 1 :(得分:1)

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

#app/config/config.yml
framework:
    templating:
        engines: ['twig']

这解决了我的问题。你可以查看这个链接 Symfony 3.4 Use view inside my bundle

答案 2 :(得分:0)

Following the docs(Symfony> = 3.4)您应该在控制器中写出模板的路径,如下所示:

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

答案 3 :(得分:0)

这对我有用:

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


希望它:)

答案 4 :(得分:0)

捆绑参考模板¶

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

@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.

答案 5 :(得分:0)

在symfony 4中使用此:

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