Thanks for the encouragement. I think for now I’ll stick to just tags. Can i be a pain and get en example of how to use tags in my dropdown instead of child pages.
I have only one page that has ‘children’, and those children are all linked to tags. There are no sub pages any more for any other page. So just 4 pages without children, then a 5th page that has the child articles based on tags. So essentially I don’t need to show subpages in the menu, just tags for the parent page that has them. Does that make sense?
In your controller or template for the $item page, you would then filter by that parameter:
<?php
return function($site, $pages, $page) {
$children = $page->children()->visible();
if($category = param('category') {
// filter by category (or whatever the name of the field in your blueprint
$children = $page->children()->visible()->filterBy('category', $category);
}
return compact('children');
};
$children = $page->children()->visible();
if($category = param('category')) {
// filter by category (or whatever the name of the field in your blueprint
$children = $page->children()->visible()->filterBy('category', $category);
}
But it should go into the products template, not the individual product…
By the way, if you use checkboxes instead of the tags field (or a mulit-select field), all the code would be the same. Checkboxes are stored in the same way in the content file as tags, that is as a comma separated string.
<?php
$children = $page->children()->visible();
if($category = param('category')) {
// filter by category (or whatever the name of the field in your blueprint
$children = $page->children()->visible()->filterBy('tags', $category);
}
?>
Blueprint is:
title: Product
pages: false
files:
sortable: true
fields:
title:
label: Title
type: title
text:
label: Text
type: textarea
tags:
label: Tags
type: tags
lower: true
Sure - probably my bad use of terminology. I’m not using categories at all. I was simply making use of tags in order to categorise the articles and give me a hook that I could use to filter the articles. It’s as simple as that.