Move Twig link filter and url_param and form_param functions to PicoTwigExtension

This commit is contained in:
Daniel Rudolf 2016-12-12 17:08:40 +01:00
parent 1f35346f53
commit 46f5d3d56d
No known key found for this signature in database
GPG key ID: A061F02CD8DE4538
2 changed files with 16 additions and 6 deletions

View file

@ -1500,11 +1500,6 @@ class Pico
$this->twig->addExtension(new Twig_Extension_Debug());
$this->twig->addExtension(new PicoTwigExtension($this));
// register link filter and the url_param and form_param functions
$this->twig->addFilter(new Twig_SimpleFilter('link', array($this, 'getPageUrl')));
$this->twig->addFunction(new Twig_SimpleFunction('url_param', array($this, 'getUrlParameter')));
$this->twig->addFunction(new Twig_SimpleFunction('form_param', array($this, 'getFormParameter')));
// 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

View file

@ -51,7 +51,7 @@ class PicoTwigExtension extends Twig_Extension
}
/**
* Returns the Twig filters markdown, map and sort_by
* Returns a list of Pico-specific Twig filters
*
* @see Twig_ExtensionInterface::getFilters()
* @return Twig_SimpleFilter[] array of Pico's Twig filters
@ -62,6 +62,21 @@ class PicoTwigExtension extends Twig_Extension
'markdown' => new Twig_SimpleFilter('markdown', array($this, 'markdownFilter')),
'map' => new Twig_SimpleFilter('map', array($this, 'mapFilter')),
'sort_by' => new Twig_SimpleFilter('sort_by', array($this, 'sortByFilter')),
'link' => new Twig_SimpleFilter('link', array($this->pico, 'getPageUrl'))
);
}
/**
* Returns a list of Pico-specific Twig functions
*
* @see Twig_ExtensionInterface::getFunctions()
* @return Twig_SimpleFunction[] array of Pico's Twig functions
*/
public function getFunctions()
{
return array(
'url_param' => new Twig_SimpleFunction('url_param', array($this->pico, 'getUrlParameter')),
'form_param' => new Twig_SimpleFunction('form_param', array($this->pico, 'getFormParameter'))
);
}