PHP Twig 启动器问题(找不到模板)

PHP Twig starter Problems (doesn't find templates)

我的 google foo 达到了极限:/。我希望你能帮助我。 Twig 找不到我的模板,我遍历了很多随机的互联网发现:D。

当我访问 index.php(取消最后一行的注释)时它有效,但当我访问网络服务器时它不起作用。tld/control/xyz/sitename.php.

以下结构:

index.php

require_once 'lib/Twig/Autoloader.php';
Twig_Autoloader::register();
$template_dir = 'templates/categoryA';
$loader = new Twig_Loader_Filesystem($template_dir);
$twig = new Twig_Environment($loader, array('debug' => true,));
// echo $twig->render('sitename.phtml', array('name' => 'Rapunzel'));

/control/xyz/sitename.php

require_once '../../index.php';
$template = $twig->loadTemplate($template_dir . '/sitename.phtml');
echo $template->render(array('name' => 'Rapunzel'));

错误信息

Uncaught exception 'Twig_Error_Loader' with message 'The "templates/categoryA" directory does not exist.' in /asdf/asdf/TEST_twig/lib/Twig/Loader/Filesystem.php on line 94

我试过的

我尝试通过数组加载多个模板(作为 Twig_Loader_Filesystem 的参数),另外我尝试了 $loader->addPath() 但没有成功:/.

我不知道,为什么它没有更早的工作。我的 "solution" 现在可以用了。但它可能不是一个好的 :D.

index.php

require_once 'lib/Twig/Autoloader.php';
Twig_Autoloader::register();
$template_dir = (
    __DIR__.'/templates/categoryA',
    __DIR__.'/templates'
);
$loader = new Twig_Loader_Filesystem($template_dir);
$twig = new Twig_Environment($loader, array('debug' => true,));

sitename.php

require_once '../../index.php';
$template = $twig->loadTemplate('sitename.phtml');
echo $template->render(array('name' => 'Rapunzel'));