I'm trying to build simple Slim application with Twig template. The code is
<?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();
After running application I can see nothing in my browser.
But when I comment lines
$template = $twig->loadTemplate('index.html');
echo $template->render(array());
And remove comment from line
$response->getBody()->write("Test");
I can see Test in my browser which means that router '/' works.
File index.html exists and it's not emply
The content of index.html file is
<!DOCTYPE html>
<html>
<head>
<title>My Webpage</title>
</head>
<body>
<h1>My Webpage</h1>
</body>
</html>
How can I force template to be shown?