[英]PHP Twig starter Problems (doesn't find templates)
我的谷歌foo在其极限:/。 我希望你能帮助我。 Twig找不到我的模板,因此我在很多随机的Internet搜索结果中进行了迭代:D。
当我访问index.php(取消最后一行的注释)时,它可以工作,但是当我访问webserver.tld / control / xyz / sitename.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'));
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(),但没有成功:/。
我不知道,为什么它没有更早地起作用。 我的“解决方案”现在有效。 但这可能不是一个好方法: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'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.