Commit 76b52992 by Alexander Makarov

Better alias handling for Twig extension

parent 0ed6355e
......@@ -144,15 +144,27 @@ class ViewRenderer extends BaseViewRenderer
{
$this->twig->addGlobal('this', $view);
$loader = new \Twig_Loader_Filesystem(dirname($file));
$this->addAliases($loader, Yii::$aliases);
$this->twig->setLoader($loader);
return $this->twig->render(pathinfo($file, PATHINFO_BASENAME), $params);
}
foreach (Yii::$aliases as $alias => $path) {
if (is_string($path) && is_dir($path)) {
/**
* Adds aliases
*
* @param \Twig_Loader_Filesystem $loader
* @param array $aliases
*/
protected function addAliases($loader, $aliases)
{
foreach ($aliases as $alias => $path) {
if (is_array($path)) {
$this->addAliases($loader, $path);
} elseif (is_string($path) && is_dir($path)) {
$loader->addPath($path, substr($alias, 1));
}
}
$this->twig->setLoader($loader);
return $this->twig->render(pathinfo($file, PATHINFO_BASENAME), $params);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment