Twig slim framework 3,无法呈现html页面

Twig slim framework 3,无法呈现html页面,twig,slim,slim-3,Twig,Slim,Slim 3,我使用twig view呈现html,目前无法更改返回到浏览器的内容类型,我可以看到slim返回的内容类型为json,而不是html内容,因此所有代码都显示在浏览器中 $app->get('/',function(Request $req,Response $res,array $args) use ($app){ $container = $app->getContainer(); $container->view->render($r

我使用twig view呈现html,目前无法更改返回到浏览器的内容类型,我可以看到slim返回的内容类型为json,而不是html内容,因此所有代码都显示在浏览器中

 $app->get('/',function(Request $req,Response $res,array $args) use ($app){
        $container = $app->getContainer();
        $container->view->render($res, 'test.html',[]);
    });

尝试返回如下响应:

return $container->view->render($res, 'test.html', []);

添加到Zamrony p.Juhara 我发现我放置的中间件正在编辑作为json内容返回的响应 ->withHeader(“内容类型”、“应用程序/json”)

因此浏览器只收到json内容响应,因此它将所有代码作为json内容而不是内容类型:“text/html”转储,
这就解决了我的问题

谢谢你的回复,这是浪费了这么多时间后的另一个问题。我意识到我保留了阻止它的中间件$app->add(function($req,$res,$next){$response=$next($req,$res);return$response/->withHeader(“Content Type”,“application/json”)/->withHeader('Access-Control-Allow-Origin',')->withHeader('Access-Control-Allow-Origin','*')->withHeader('Access-Control-Allow-Headers','X-request-With,Content-Type,Accept,Origin,Authorization')->withHeader('Access-Control-Allow-Methods','GET,POST,PUT,DELETE,PATCH,OPTIONS'););
/*
CORS
*/
$app->add(function ($req, $res, $next) {
    $response = $next($req, $res);
    return $response
            //->withHeader("Content-Type", "application/json")
            //->withHeader('Access-Control-Allow-Origin', 'http://localhost:2222/')
            ->withHeader('Access-Control-Allow-Origin', '*')
            ->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization')
            ->withHeader('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE,PATCH,OPTIONS');
});