|
@@ -1109,6 +1109,9 @@ class Pico
|
|
/**
|
|
/**
|
|
* Registers the twig template engine
|
|
* Registers the twig template engine
|
|
*
|
|
*
|
|
|
|
+ * This method also registers Picos core Twig filters `link` and `content`
|
|
|
|
+ * as well as Picos {@link PicoTwigExtension} Twig extension.
|
|
|
|
+ *
|
|
* @see Pico::getTwig()
|
|
* @see Pico::getTwig()
|
|
* @return void
|
|
* @return void
|
|
*/
|
|
*/
|
|
@@ -1119,22 +1122,13 @@ class Pico
|
|
$this->twig->addExtension(new Twig_Extension_Debug());
|
|
$this->twig->addExtension(new Twig_Extension_Debug());
|
|
$this->twig->addExtension(new PicoTwigExtension($this));
|
|
$this->twig->addExtension(new PicoTwigExtension($this));
|
|
|
|
|
|
- $this->registerTwigFilter();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Registers Picos additional Twig filters
|
|
|
|
- *
|
|
|
|
- * @return void
|
|
|
|
- */
|
|
|
|
- protected function registerTwigFilter()
|
|
|
|
- {
|
|
|
|
- $pico = $this;
|
|
|
|
-
|
|
|
|
- // link filter
|
|
|
|
|
|
+ // register link filter
|
|
$this->twig->addFilter(new Twig_SimpleFilter('link', array($this, 'getPageUrl')));
|
|
$this->twig->addFilter(new Twig_SimpleFilter('link', array($this, 'getPageUrl')));
|
|
|
|
|
|
- // content filter
|
|
|
|
|
|
+ // register content filter
|
|
|
|
+ // we pass the $pages array by reference to prevent multiple parser runs for the same page
|
|
|
|
+ // this is the reason why we can't register this filter as part of PicoTwigExtension
|
|
|
|
+ $pico = $this;
|
|
$pages = &$this->pages;
|
|
$pages = &$this->pages;
|
|
$this->twig->addFilter(new Twig_SimpleFilter('content', function ($page) use ($pico, &$pages) {
|
|
$this->twig->addFilter(new Twig_SimpleFilter('content', function ($page) use ($pico, &$pages) {
|
|
if (isset($pages[$page])) {
|
|
if (isset($pages[$page])) {
|
|
@@ -1147,15 +1141,6 @@ class Pico
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}));
|
|
}));
|
|
-
|
|
|
|
- // markdown filter
|
|
|
|
- $this->twig->addFilter(new Twig_SimpleFilter('markdown', function ($markdown) use ($pico) {
|
|
|
|
- if ($pico->getParsedown() === null) {
|
|
|
|
- throw new LogicException("Unable to parse file contents: Parsedown instance wasn't registered yet");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return $pico->getParsedown()->text($markdown);
|
|
|
|
- }));
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|