我正在尝试使用Twig模板构建简单的Slim应用程序。代码是
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../vendor/autoload.php';
require_once '../vendor/twig/twig/lib/Twig/Autoloader.php';
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem('../public');
$twig = new Twig_Environment($loader, array(
'cache' => '/cache',
));
$app = new \Slim\App;
$app->get('/', function (Request $request, Response $response) use ($twig) {
$template = $twig->loadTemplate('index.html');
echo $template->render(array());
//$response->getBody()->write("Test");
});
$app->run();
运行应用程序后,我在浏览器中看不到任何内容。
但是当我评论行
时 $template = $twig->loadTemplate('index.html');
echo $template->render(array());
从
删除评论$response->getBody()->write("Test");
我可以在浏览器中看到Test,这意味着路由器'/'可以工作。
文件index.html存在且不是空的
index.html文件的内容是
<!DOCTYPE html>
<html>
<head>
<title>My Webpage</title>
</head>
<body>
<h1>My Webpage</h1>
</body>
</html>
如何强制显示模板?