dongqiao3214 2015-08-07 13:07
浏览 22
已采纳

不能使树枝模板沙箱工作

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.

  • 写回答

2条回答 默认 最新

  • dongqin1861 2015-08-12 07:34
    关注

    That was just me not looking at what I should look at. The cache directory was generated, when index.html was empty. I should have cleared the cache - that's all...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址