1
我用了这个问题How do I specify two locations for Twig templates?如何获得
$template = isset($config->template) ? $config->template : 'default';
$templates_dir = $root . 'templates' . DIRECTORY_SEPARATOR;
if (isset($config->template) && $config->template != 'default') {
$template = array($templates_dir . $config->template, $templates_dir . 'default');
} else {
$template = $templates_dir . 'default';
}
$loader = new Twig_Loader_Filesystem($template);
发现了两个枝杈模板路径树枝模板的路径,我有这样的代码:
function render($request, $page, $data = array()) {
global $twig, $config;
$template = isset($config->template) ? $config->template : 'default';
$base = baseURI($request);
return $twig->render($page, array_merge(array(
"path" => $base . '/templates/' . $template,
"root" => $base
), $data));
}
什么,我需要的是获取模板的路径,以便我可以将其用作'path'
变量(这样我可以使用"{{path}}/img/foo.png"
之类资产的当前路径)。