Ok giving back… ; )
site/config:
c::set('routes', array(
array(
'pattern' => '(:all)/(:any)',
'action' => function($target, $tag) {
$data = array('tag' => $tag);
$page = page($target .'/'. $tag);
$targetPage = page($target);
if (!$targetPage) {
go('error');
} else {
if($page) {
return site()->visit($page->uri());
} else {
return array($target, $data);
}
}
}
)
));
site/controllers/page.php
return function ($site, $pages, $page, $data) {
$children = $page->children()->visible();
if (isset($data['tag'])) {
$tagged = urldecode($data['tag']);
$children = $children->filterBy('tags', $tagged, ',');
if($children->count() == 0){
go('error');
}
}
return compact('children', 'tagged');
}
site/snippets/children.php
<?php $children = $data; ?>
<?php foreach($children as $child): ?>
<?php echo $child->title() ?>
<?php if(!$child->tags()->empty()): ?>
<p>
<?php foreach($child->tags()->split(',') as $tag): ?>
<a href="<?php echo $page->url() .'/'. $tag ?>">
<?php echo html($tag) ?>
</a>
<?php endforeach ?>
</p>
<?php endif ?>
<?php endforeach ?>
site/snippets/tags.php
<?php
$tags = $page->children()->visible()->pluck('tags', ',', true);
if($tags): ?>
<ul class="tags">
<li><a href="<?php echo $page->url() ?>">All</a></li>
<?php foreach($tags as $tag): ?>
<li>
<a <?php e($tag == $tagged, ' class="active"') ?>
href="<?php echo $page->url() . '/' . $tag ?>">
<?php echo $tag ?>
</a>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>
site/template/page.php
<?php snippet('tags'); ?>
<?php snippet('children', array('data' => $children)); ?>