[英]Symfony 4 - Unable to find template
我將我的項目更新為 Symfony4。 當我使用表單訪問某個頁面時,出現此錯誤:
Unable to find template "StarRatingBundle::rating.html.twig"
(looked into: /templates, /templates, \vendor\symfony\twig-bridge/Resources/views/Form).
我使用blackknight467/star-rating-bundle
一個包,它提供了一個樹枝擴展來擁有一個星級系統。 錯誤中的模板位於此包Resources/views
文件夾中。
樹枝.yaml :
twig:
paths: ['%kernel.project_dir%/templates']
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
form_themes:
- 'Form/fields.html.twig'
Symfony 4+ 不支持“x:x:x.html.twig”符號。 你需要安裝composer require templating
然后通過添加在您的 framework.yaml 中激活它
templating: engines: ['twig']
。
文件 > 使緩存無效並重新啟動。 這應該允許 Symfony 找到您的模板。
我在創建 symfony 5 包時遇到了這個問題。 確保將樹枝模板保存在<project-folder>/Resources/views
文件夾中。 在您的 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',
]);
}
}
是沒有包后綴的包的名稱。 例如,如果您將包注冊為Example\\HelloBundle\\ExampleHelloBundle::class => ['all' => true],
在 Bundles.php 中<BundleName>
是 ExampleHello
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.