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条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?