Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Fix #12 missing Tpl::$data in snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
Florens Verschelde committed Oct 4, 2016
1 parent 6fa5a9c commit 2214e48
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/TwigRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function __construct()
* @param bool $return
* @return string|null
*/
public function template($filePath, $tplData=[], $return = true)
public function render($filePath, $tplData=[], $return = true)
{
// Remove the start of the templates path, since Twig asks for a path
// starting from one of the setup directories.
Expand Down
14 changes: 10 additions & 4 deletions src/TwigTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TwigTemplate extends Template
*/
public function file($name)
{
$usephp = c::get('twig.usephp', true);
$usephp = C::get('twig.usephp', true);
$base = str_replace('\\', '/', $this->kirby->roots()->templates().'/'.$name);
$twig = $base . '.twig';
$php = $base . '.php';
Expand Down Expand Up @@ -65,15 +65,21 @@ public function render($template, $data = [], $return = true)
throw new Exception('The template could not be found');
}

// merge and register the template data globally
$tplData = Tpl::$data;
Tpl::$data = array_merge(Tpl::$data, $data);

// load the template
if (pathinfo($file, PATHINFO_EXTENSION) === 'twig') {
$fullData = array_merge(Tpl::$data, $data);
$twigRenderer = new TwigRenderer();
$result = $twigRenderer->template($file, $fullData, $return);
$twig = new TwigRenderer();
$result = $twig->render($file, Tpl::$data, $return);
} else {
$result = Tpl::load($file, $data, $return);
}

// reset the template data
Tpl::$data = $tplData;

return $result;
}
}

0 comments on commit 2214e48

Please sign in to comment.