Skip to content

Commit

Permalink
Fixing Twig Filters being added too late on latest Pico
Browse files Browse the repository at this point in the history
  • Loading branch information
matschundbrei committed Apr 3, 2019
1 parent 804dbaf commit acac004
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions PicoPagesList.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,11 @@ protected function onCurrentPageDiscovered(
* 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 +91,24 @@ 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)
{
$twig = $this->getPico()->getTwig();
$twigVariables['nested_pages'] = $this->items;
}

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

0 comments on commit acac004

Please sign in to comment.