Can't figure out why "hasPages" isn't skipped when there are no pages listed

Hi,

Moved all pages under “listed” to “unlisted” but below code won’t go to <?php snippet('empty') ?>.

<?php if ($page->listed()->hasPages()): ?>

  <?php if ($page->layout()->value() === 'grid'): ?>
    <?php snippet('posts-grid') ?>
  <?php else: ?>
    <?php snippet('posts-list') ?>
  <?php endif ?>

<?php else: ?>

  <?php snippet('empty') ?>

<?php endif ?>

Tried with isNotEmpty() instead of hasPages() but then when there are pages under “listed” nothing is shown :thinking:

There is no $page->listed() method. What is that line supposed to do?

This is the blueprint:

tabs:

  posts:
    columns:
      - width: 1/3
        sections:
          drafts:
            extends: sections/posts
            headline: Drafts
            image: page.cover.toFile
            status: draft
          unlisted:
            extends: sections/posts
            headline: Unlisted
            image: page.cover.toFile
            status: unlisted
      - width: 2/3
        sections:
          listed:
            extends: sections/posts
            headline: Published
            image:
              cover: true
              query: page.cover.toFile
              ratio: 2/1
            layout: cards
            status: listed

If there are posts with status “listed” I’m listing those posts on that page. Otherwise I’m showing a message that tells there are no posts.

Yes, but a section cannot be called from the content, because it’s not stored in the file. Call the page’s children and filter by listed: $page->listedChildren() or

if ($page->hasListedChildren()){
  // do stuff
}
1 Like

Thanks so much as always!