Ich bin mit zwei Zweig-Vorlage Pfade in dieser Frage gefunden How do I specify two locations for Twig templates?Wie Weg der Zweig-Vorlage erhalten
$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);
und ich habe Code wie folgt:
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));
}
und was ich brauche, ist zu get Pfad der Vorlage, so kann ich es als 'path'
Variable verwenden (so kann ich den aktuellen Pfad für Assets wie "{{path}}/img/foo.png"
verwenden).