symfony 没有引擎能够与模板一起工作

svujldwt  于 2023-11-22  发布在  其他
关注(0)|答案(1)|浏览(144)

我正在尝试渲染一个主题索引文件,我试图导入到pimcore来使用。我已经把主题文件夹放在app/Resources/views中。
我已将以下内容添加到routing.yml文件中

index:
    path: /static/dist/index.html
    controller: AppBundle\Controller\indexController::index

字符串
下面是我的控制器名为indexController.php

<?php
namespace Appbundle\Controller;

use Pimcore\Controller\FrontendController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

class indexController extends FrontendController
{
    /**
    * @Route("/static/dist/index.html", name="homepage")
    */
    public function index()
    {
        return $this->render('static/dist/index.html');
    }
}


当我尝试导航到localhost/static/dist/index.html时,我得到以下错误:

No engine is able to work with the template "static/dist/index.html".

ljsrvy3e

ljsrvy3e1#

Pimcore文档指定使用以下选项之一:

  • 或渲染命令返回字符串
  • 或模板名称在注解返回数组中

样品名称:

class DefaultController extends FrontendController
{   

    public function myAction()
    {
        return $this->render('content/default.html.twig', ["foo" => "bar"]);
    }

    /**
     * Example using the #[Template] attribute to resolve the view. 
     * The frontend controller also provides methods to add response headers or via attributes without having
     * access to the final response object (as it is automatically created when rendering the view).
     *
     */
     #[Template('/default/header.html.twig')]
     #[ResponseHeader(key: "X-Foo", values: ["123456", "98765"])]
    public function headerAction(Request $request)
    {
        // schedule a response header via code
        $this->addResponseHeader('X-Foo', 'bar', false, $request);
        
        return ["foo" => "bar"];
    }
}

字符串
请参阅此处的文档:

相关问题