Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ViewRenderer.php #3907

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions extensions/twig/ViewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,30 @@ class ViewRenderer extends BaseViewRenderer
/**
* @var \Twig_Environment twig environment object that do all rendering twig templates
*/


public $define_layout = NULL;
/**
* @var string the directory pointing to where the extra layout template folder.
*/

public $twig;

public $loader;

public function init()
{
$this->twig = new \Twig_Environment(null, array_merge([
// Adding extra template layout
if (!empty($this->define_layout)) {

$this->loader = new \Twig_Loader_Filesystem($_SERVER['DOCUMENT_ROOT'].$this->define_layout);
}
else
{
$this->loader = NULL;
}

$this->twig = new \Twig_Environment($this->loader, array_merge([
'cache' => Yii::getAlias($this->cachePath),
'charset' => Yii::$app->charset,
], $this->options));
Expand Down Expand Up @@ -154,8 +173,16 @@ public function init()
public function render($view, $file, $params)
{
$this->twig->addGlobal('this', $view);
$this->twig->setLoader(new TwigSimpleFileLoader(dirname($file)));

if($this->loader)
{
$this->loader->addPath(dirname($file));
}
else
{
$this->twig->setLoader(new TwigSimpleFileLoader(dirname($file)));
}

return $this->twig->render(pathinfo($file, PATHINFO_BASENAME), $params);
}

Expand Down