In Panel select and list pages based on tag

I have a portfolio page with child case study pages. Some case studies are listed. Some older ones are unlisted. All case studies are tagged with the type of ‘service’ provided. There are three tags.

Separate from the portfolio page there are three pages describing each type of service (these have the same Blueprint and template). I’d like these pages to show the listed case studies (child pages of the portfolio page) that match the specific tag.

So for example, the ‘Branding’ page, in the Panel, should be able to select and show only listed case studies that are tagged with ‘branding’. And the Graphic Design page should be able in the Panel to select by ‘graphic design’.

I guess I would have a Pages Section. With some sort of toggle(?) to be able to select pages that are tagged with the tag I need to filter by.

Is that possible?? And if so, any pointers on how to do it?

… I guess this might be easier if the three ‘services’ pages have three different Blueprint and templates?

Why do you need to show them in the Panel?

And select means you don’t want all, but only a few? Otherwise, select does not make sense.

Apart from that, I’d like to point you again to what I wrote here, as this still does not seem to clear to you:

I don’t know the right words to use!

I have three pages:

  1. Branding
  2. Graphic design
  3. Exhibition design

At the moment these pages share the same template and blueprint.

Is it possible, for example, to get the branding page to display:
Portfolio page > child pages > that are listed > and tagged with ‘branding’?

So I guess in the Panel I’d need some sort of toggle, on each page, to be able to choose the appropriate tag I want to display?

===

If this isn’t possible, then I guess I could create three different templates and blueprints for the different pages and use fields > pages with a query to get pages by tag.

My main question is why you need to display them in the Panel in the first place instead of just showing a filtered list of pages in the frontend?

E.g.

$useCases = $page->children()->listed()->filterBy('tags', $page->slug(), ','); // so page->slug would be `branding`, etc.

To display them in the panel in a pages section, you can use the query prop: Pages section | Kirby CMS (instead of hard coding the value, use page.slug)

But that would not be “select”, but “list”.

Select: to choose (as by fitness or excellence) from a number or group : pick out (Merriam Webster dictionary)

Hey thanks

I’m thinking that on the branding page in the Panel there would be a button/toggle/switch to get the page, in the front end, to display the case studies tagged with branding. And then on the design page in the Panel there would be the same button/toggle/switch to get that page, in the front end, to display the case studies tagged with design, etc.

If that’s not possible, I presume I’m going to need three different templates, to get the three different lists?

Branding template:

$useCases = $portfolio->children()->listed()->filterBy('tags', $page->'branding'); 

Design template:

$useCases = $portfolio->children()->listed()->filterBy('tags', $page->'design'); 

Exhibitions template:

$useCases = $portfolio->children()->listed()->filterBy('tags', $page->'exhibitions'); 

slug(), not branding, as I wrote above, instead of hardcoding something here. Then you don’t need different template, blueprints, or a toggle.

I don’t understand why you don’t try what is suggested?

I’ll give it a go tomorrow, when I’m not so tired. It will take a lot of effort for me to work out what to do with the code!

So if I use the code –

$useCases = $page->children()->listed()->filterBy('tags', $page->slug(), ','); 

– in my template, on the Branding page how do I only show the pages (case studies) tagged with ‘branding’? And on the Design page only the pages tagged with ‘design’? etc

Oh, hang on, so is that code saying filter by tags that match the page slug/URL/name? So if my page is called ‘branding’ the filter will filter by tags that match the slug ‘branding’? So my page names will need to exactly match my tag names?

That’s what I thought. If not, maybe add a field with the tag name to filter by

Okay, I get it now! Hey thanks.

I’ll try to get the code working, in the morning, when I have more time to give it

Fab, that’s work and was easy to implement. Thank you