Hi folks,
I have a Template where I loop through a set of visible subpages, kind of like a blogpost-overview. If there is no subpage available/visible, I’d like to show a message on the website, like “no posts available”. Do you a code-solution for me?
Thanks in advance, cheers, Dennis
You can use the count() method (http://getkirby.com/docs/cheatsheet/pages/count) to check if there are pages in your collection:
Quick and dirty example:
<?php if($page->children()->visible()->count() > 0): ?> // There are pages, continue with logic <?php else: ?> <span>No messages!</span> <?php endif ?>
Well thank you very much, Gerard! Perfect answer, worked exactly as intended. Thanks!