Remove Pico::registerTwig(), use Pico::getTwig() instead
This commit is contained in:
parent
80c88f2a7d
commit
773f4795f7
43
lib/Pico.php
43
lib/Pico.php
@ -431,13 +431,11 @@ class Pico
|
|||||||
);
|
);
|
||||||
|
|
||||||
// render template
|
// render template
|
||||||
$this->registerTwig();
|
|
||||||
|
|
||||||
$this->twigVariables = $this->getTwigVariables();
|
$this->twigVariables = $this->getTwigVariables();
|
||||||
$this->twigTemplate = $this->getTwigTemplate();
|
$this->twigTemplate = $this->getTwigTemplate();
|
||||||
$this->triggerEvent('onPageRendering', array(&$this->twigTemplate, &$this->twigVariables));
|
$this->triggerEvent('onPageRendering', array(&$this->twigTemplate, &$this->twigVariables));
|
||||||
|
|
||||||
$output = $this->twig->render($this->twigTemplate, $this->twigVariables);
|
$output = $this->getTwig()->render($this->twigTemplate, $this->twigVariables);
|
||||||
$this->triggerEvent('onPageRendered', array(&$output));
|
$this->triggerEvent('onPageRendered', array(&$output));
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
@ -1589,26 +1587,21 @@ class Pico
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers the Twig template engine
|
* Returns the Twig template engine
|
||||||
*
|
|
||||||
* This method also registers Pico's core Twig filters `link` and `content`
|
|
||||||
* as well as Pico's {@see PicoTwigExtension} Twig extension.
|
|
||||||
*
|
*
|
||||||
* This method triggers the `onTwigRegistered` event when the Twig template
|
* This method triggers the `onTwigRegistered` event when the Twig template
|
||||||
* engine wasn't initiated yet.
|
* engine wasn't initiated yet. When initiating Twig, this method also
|
||||||
|
* registers Pico's core Twig filters `link` and `content` as well as
|
||||||
|
* Pico's {@see PicoTwigExtension} Twig extension.
|
||||||
*
|
*
|
||||||
* @see Pico::getTwig()
|
* @see Pico::getTwig()
|
||||||
* @see http://twig.sensiolabs.org/ Twig website
|
* @see http://twig.sensiolabs.org/ Twig website
|
||||||
* @see https://github.com/twigphp/Twig Twig on GitHub
|
* @see https://github.com/twigphp/Twig Twig on GitHub
|
||||||
* @return void
|
* @return Twig_Environment|null Twig template engine
|
||||||
*/
|
*/
|
||||||
protected function registerTwig()
|
public function getTwig()
|
||||||
{
|
{
|
||||||
if ($this->twig !== null) {
|
if ($this->twig === null) {
|
||||||
// nothing to do
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$twigLoader = new Twig_Loader_Filesystem($this->getThemesDir() . $this->getConfig('theme'));
|
$twigLoader = new Twig_Loader_Filesystem($this->getThemesDir() . $this->getConfig('theme'));
|
||||||
$this->twig = new Twig_Environment($twigLoader, $this->getConfig('twig_config'));
|
$this->twig = new Twig_Environment($twigLoader, $this->getConfig('twig_config'));
|
||||||
$this->twig->addExtension(new Twig_Extension_Debug());
|
$this->twig->addExtension(new Twig_Extension_Debug());
|
||||||
@ -1635,18 +1628,6 @@ class Pico
|
|||||||
$this->triggerEvent('onTwigRegistered', array(&$this->twig));
|
$this->triggerEvent('onTwigRegistered', array(&$this->twig));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the twig template engine
|
|
||||||
*
|
|
||||||
* @see Pico::registerTwig()
|
|
||||||
* @return Twig_Environment|null Twig template engine
|
|
||||||
*/
|
|
||||||
public function getTwig()
|
|
||||||
{
|
|
||||||
if ($this->twig === null) {
|
|
||||||
$this->registerTwig();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->twig;
|
return $this->twig;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1660,10 +1641,6 @@ class Pico
|
|||||||
*/
|
*/
|
||||||
protected function getTwigVariables()
|
protected function getTwigVariables()
|
||||||
{
|
{
|
||||||
if ($this->twigVariables !== null) {
|
|
||||||
return $this->twigVariables;
|
|
||||||
}
|
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'config' => $this->getConfig(),
|
'config' => $this->getConfig(),
|
||||||
'base_dir' => rtrim($this->getRootDir(), '/'),
|
'base_dir' => rtrim($this->getRootDir(), '/'),
|
||||||
@ -1688,10 +1665,6 @@ class Pico
|
|||||||
*/
|
*/
|
||||||
protected function getTwigTemplate()
|
protected function getTwigTemplate()
|
||||||
{
|
{
|
||||||
if ($this->twigTemplate !== null) {
|
|
||||||
return $this->twigTemplate;
|
|
||||||
}
|
|
||||||
|
|
||||||
$templateName = $this->meta['template'] ?: 'index';
|
$templateName = $this->meta['template'] ?: 'index';
|
||||||
|
|
||||||
if (file_exists($this->getThemesDir() . $this->getConfig('theme') . '/' . $templateName . '.twig')) {
|
if (file_exists($this->getThemesDir() . $this->getConfig('theme') . '/' . $templateName . '.twig')) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user