[英]Symfony 4 - Unable to find template
I updated my project to Symfony4.我将我的项目更新为 Symfony4。 When I go to some page with a form I have this error appearing :
当我使用表单访问某个页面时,出现此错误:
Unable to find template "StarRatingBundle::rating.html.twig"
(looked into: /templates, /templates, \vendor\symfony\twig-bridge/Resources/views/Form).
I use blackknight467/star-rating-bundle
a bundle which provides a twig extension to have a star rating system.我使用
blackknight467/star-rating-bundle
一个包,它提供了一个树枝扩展来拥有一个星级系统。 The template in the error is located in this bundle Resources/views
folder.错误中的模板位于此包
Resources/views
文件夹中。
Twig.yaml :树枝.yaml :
twig:
paths: ['%kernel.project_dir%/templates']
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
form_themes:
- 'Form/fields.html.twig'
Symfony 4+ does not support “x:x:x.html.twig” notation. Symfony 4+ 不支持“x:x:x.html.twig”符号。 You need to install
composer require templating
你需要安装
composer require templating
then activate it in your framework.yaml by adding然后通过添加在您的 framework.yaml 中激活它
templating: engines: ['twig']
. templating: engines: ['twig']
。
Files > Invalidate caches & restart.文件 > 使缓存无效并重新启动。 This should allow Symfony to find your templates.
这应该允许 Symfony 找到您的模板。
I struggled with the issue when creating a symfony 5 bundle.我在创建 symfony 5 包时遇到了这个问题。 Make sure you keep your twig templates in
<project-folder>/Resources/views
folder.确保将树枝模板保存在
<project-folder>/Resources/views
文件夹中。 In your Controller, using HelloworldController
as an example:在您的 Controller 中,以
HelloworldController
为例:
`<?php
namespace Example\HelloBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class HelloController extends AbstractController
{
public function index(): Response
{
return $this->render('@<BundleName>/hello/index.html.twig', [
'controller_name' => 'HelloController',
]);
}
}
is the name of your bundle without the bundle suffix.是没有包后缀的包的名称。 For example if you registered your bundle as
Example\\HelloBundle\\ExampleHelloBundle::class => ['all' => true],
in Bundles.php then <BundleName>
is ExampleHello例如,如果您将包注册为
Example\\HelloBundle\\ExampleHelloBundle::class => ['all' => true],
在 Bundles.php 中<BundleName>
是 ExampleHello
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.