Skip to content

Commit

Permalink
Merge pull request #19 from matschundbrei/master
Browse files Browse the repository at this point in the history
Fixing Twig Filters being added too late on latest Pico
  • Loading branch information
nliautaud authored May 10, 2019
2 parents 804dbaf + 6a47b58 commit ead799a
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions PicoPagesList.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,13 @@ protected function onCurrentPageDiscovered(
/**
* Register `$this` in the Twig `{{ PagesList }}` variable.
*
* Triggered before Pico renders the page
*
* @see Pico::getTwig()
* @see DummyPlugin::onPageRendered()
* @param string &$templateName file name of the template
* @param array &$twigVariables template variables
* @param Twig_Environment &$twig Twig instance
* @return void
*/
public function onPageRendering(string &$templateName, array &$twigVariables)
public function onTwigRegistered(Twig_Environment &$twig)
{
$twig = $this->getPico()->getTwig();
$twigVariables['nested_pages'] = $this->items;

$twig->addFilter(new Twig_SimpleFilter('navigation', function($pages) {
return $this->output($pages);
}));
Expand All @@ -96,6 +90,23 @@ public function onPageRendering(string &$templateName, array &$twigVariables)
}, array('is_variadic' => true)));
}

/**
* Register `$this` in the Twig `{{ PagesList }}` variable.
*
* Triggered before Pico renders the page
*
* @see Pico::getTwig()
* @see DummyPlugin::onPageRendered()
* @param string &$templateName file name of the template
* @param array &$twigVariables template variables
* @return void
*/

public function onPageRendering(string &$templateName, array &$twigVariables)
{
$twigVariables['nested_pages'] = $this->items;
}

/**
* Create the nested pages array according to the pages paths.
*
Expand Down

0 comments on commit ead799a

Please sign in to comment.