Hi,
I have an site with appointments and I use childpages as categories.
On the appointmenttemplate I parse all apointments with
$site->index()->filterBy('template', 'appointment')->visible()
to get the grandchilds for a overviewpage. But here I have the problem that if I set the categorypage on invisible they child will visible further. How can I set the grandchilds also on invisible automatic?
Cheers
The first option would be to fix it in your template, by checking if the parent is visible when you’re assembling your collection.
The second options is to work with a hook:
https://getkirby.com/docs/developer-guide/advanced/hooks
You could use the panel.page.hide
hook to hide all children, if the parent page is hidden.
You could also try to use the panel.page.update
to also change back from hidden to visible.
1 Like
I’d definitely do it in the template. Automatically setting every appointment to invisible when making the category invisible means that every manual setting gets reset and the user needs to make the appointments visible manually again after making the category visible.
Also: Instead of $site->index()
, consider just using children()
, it has a much higher performance for your use-case. Here’s an example that also filters out invisible categories:
<?php foreach($page->children()->visible() as $category): ?>
<?php foreach($category->children()->filterBy('template', 'appointment')->visible() as $appointment): ?>
...
<?php endforeach ?>
<?php endforeach ?>
1 Like
Hi,
thanks for your helpassistance.
I didn’t thought to use two foreach.