I want to make a sandbox using Twig templating.
This is my dir structure:
* cache/ - writable
* templates/
* index.html
* vendor/
* Twig - twig's content from GitHub
* index.php
The problem I'm having is that $twig->render isn't generating any output and I don't know why. I'm trying to follow the basics tutorial.
this is my index.php file:
<?php
$twig_lib = __DIR__ . '/vendor/Twig/lib/Twig';
$twig_templates = __DIR__ . '/templates';
$twig_cache = __DIR__ . '/cache'; // remember to `chmod 777 cache` (make this directory writable)
require_once $twig_lib . '/Autoloader.php';
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem($twig_templates);
$twig = new Twig_Environment($loader, array(
'cache' => $twig_cache,
));
$output = $twig->render('index.html', array(
'a_variable' => 'Hello World',
'navigation' => array(
array(
'href' => 'http://twig.sensiolabs.org/doc/intro.html#basic-api-usage',
'caption' => 'Basic Twig usage'
),
array(
'href' => 'http://twig.sensiolabs.org/',
'caption' => 'Twig main webpage'
)
)
));
echo $output;
var_dump($output);
$output is just an empty string here. Apache WWW server is not throwing any errors (checked in logs). Twig itself is loaded correctly, all paths are configured correctly as well.
This is my index.html (same as in the tutorial):
<!DOCTYPE html>
<html>
<head>
<title>My Webpage</title>
</head>
<body>
<ul id="navigation">
{% for item in navigation %}
<li><a href="{{ item.href }}">{{ item.caption }}</a></li>
{% endfor %}
</ul>
<h1>My Webpage</h1>
{{ a_variable }}
</body>
</html>
Please tell me what am I doing wrong.