Skip to content

Instantly share code, notes, and snippets.

@Schlaefer
Created March 24, 2015 16:09
Show Gist options
  • Save Schlaefer/619eba113980c2928c38 to your computer and use it in GitHub Desktop.
Save Schlaefer/619eba113980c2928c38 to your computer and use it in GitHub Desktop.
in template:
{% for page in myPages %}
{{ page.getContent }}
{% endfor %}
<?php
namespace Phile\Plugin\Phile\DemoPlugin;
use Phile\Core\Registry;
use Phile\Repository\Page;
class Plugin extends \Phile\Plugin\AbstractPlugin implements \Phile\Gateway\EventObserverInterface
{
public function __construct()
{
\Phile\Event::registerEvent('before_render_template', $this);
\Phile\Event::registerEvent('request_uri', $this);
}
public function on($eventKey, $data = null)
{
if ($eventKey === 'request_uri') {
$this->url = $data['uri'];
}
if ($eventKey !== 'before_render_template') {
return;
}
$repository = new Page();
$orgPage = $repository->findByPath($this->url);
$pages = [$orgPage];
$needed = 4;
$next = 2;
$page = $orgPage;
while ($needed && $next) {
$page = $page->getNextPage();
if (!$page) {
break;
}
array_push($pages, $page);
$needed--;
$next--;
}
$page = $orgPage;
while ($needed) {
$page = $page->getPreviousPage();
if (!$page) {
break;
}
array_unshift($pages, $page);
$needed--;
}
$templateVars = Registry::get('templateVars');
$templateVars['myPages'] = $pages;
Registry::set('templateVars', $templateVars);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment