我想用Twig模板制作一个沙箱。
这是我的目录结构:* cache/ - writable
* templates/
* index.html
* vendor/
* Twig - twig's content from GitHub
* index.php
我遇到的问题是,$树枝->渲染不产生任何输出,我不知道为什么。我正在尝试遵循基础教程。
这是我的index.php文件
<?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在这里只是一个空字符串。Apache WWW服务器没有抛出任何错误(在日志中检查)。Twig本身被正确加载,所有的路径也被正确配置。
这是我的index.html(与教程中相同):
<!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>
请告诉我我做错了什么
那只是我没有看我应该看的东西。日志含义当index.html为空时生成缓存目录。
你链接到的教程页面建议你应该要求作曲家的自动加载器:require_once 'vendor/autoloader.php';
。
你正在加载一个不存在的文件:require_once '/vendor/Twig/lib/Twig/Autoload.php';
这个文件不存在,使用缺省的编译器安装Twig
编辑:我在vendor/twig/twig/lib/Twig/Autoloader.php
发现了一个自动装填机,这与你的路径略有不同。
听起来你关闭了错误报告。你可以这样打开它:
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);