Hi,
I’m having some difficulty with something pretty simple in my opinion, but I’m probably missing something quite basic. Following the recipe Filter collections by tags, I created a menu to filter a collection of projects. I am trying to add an “active” class to the menu item when selected, but I guess isActive() and isOpen() are not the right way. Would appreciate any help. Thanks
Controller:
return function($page) {
// fetch the basic set of pages
$projects = $page->children()->listed();
// fetch all categories
$category = $projects->pluck('category', ',', true);
// add the category filter
if($category = param('category')) {
$projects = $projects->filterBy('category', $category, ',');
}
return compact('projects', 'category');
};
And then:
$categories = $site->find('works')->children()->listed()->pluck('category', ',', true);
sort($categories);
?>
<ul>
<?php foreach($categories as $category): ?>
<li //Add the active class here>
<a href="<?= url('works', ['params' => ['category' => $category]]) ?>">
<?= html($category) ?>
</a>
</li>
<?php endforeach ?>