Php 带细枝模板的简单Slim应用程序

Php 带细枝模板的简单Slim应用程序,php,twig,slim,Php,Twig,Slim,我正在尝试用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_A

我正在尝试用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();
并从行中删除注释

$response->getBody()->write("Test");
我可以在我的浏览器中看到测试,这意味着路由器“/”可以工作

存在index.html文件,但该文件不可用

index.html文件的内容是

<!DOCTYPE html>
<html>
    <head>
        <title>My Webpage</title>
    </head>
    <body>
        <h1>My Webpage</h1>
    </body>
</html>

我的网页
我的网页

如何强制显示模板?

显示错误报告,并将调试设置为true,以验证您的检查结果?@MikaTuupola感谢您的github项目。它对我很有用,我可以将细枝模板引擎连接到我的应用程序。我是php新手,一开始并没有意识到我不能在slim中简单地获取和运行twig引擎。调用此引擎必须使用某种包装器。请打开错误报告,并将调试设置为true。您检查了吗?@MikaTuupola感谢您的github项目。它对我很有用,我可以将细枝模板引擎连接到我的应用程序。我是php新手,一开始并没有意识到我不能在slim中简单地获取和运行twig引擎。它必须是某种包装器才能调用此引擎。
<!DOCTYPE html>
<html>
    <head>
        <title>My Webpage</title>
    </head>
    <body>
        <h1>My Webpage</h1>
    </body>
</html>