【发布时间】:2011-10-27 06:04:29
【问题描述】:
我想知道如何从完整路径加载模板(如 FILE 常量)。
实际上你必须像这样为模板设置一个“根”路径:
require_once '/path/to/lib/Twig/Autoloader.php';
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem('/path/to/templates');
$twig = new Twig_Environment($loader, array(
'cache' => '/path/to/compilation_cache',
));
然后:
$template = $twig->loadTemplate('index.html');
echo $template->render(array('the' => 'variables', 'go' => 'here'));
我想用完整路径而不是文件名来调用 loadTemplate 方法。
我该怎么办?
我不想为这样的事情创建自己的加载器..
谢谢
【问题讨论】:
标签: php templates template-engine twig