List all pages on template

Greeting,

How do I list all the pages in a template file? When I insert this code
$ newsletters = $ site-> find (‘newsletter-list’);
** var_dump ($ newsletters);** then throws me “null”.

I am new to this CMS and still learning so I would love for you to help me.

  1. I would like to list these pages on the template I have already set up on the “Newsletter Achive” page.

  2. The page where I want to display the listed pages but only on the page not in the control panel.

Thanks in advance! :slight_smile:

Is newsletter-list the foldername of the newsletter archive page? Please post your folder structure.

Hi,

Yes, the folder name is newsletter archive.

This is newsleter-list.yml

title: Newsletters

options:
  url: true
  status: true
  delete: true

  columns:
  left:
    width: 2/3
    sections:
      newsletters:  
        extends: sections/newsletters
        headline: Newsletters
        status: all

And file sectons/newsletters

type: pagetable
headline: Newsletters
sortBy: from desc
template: newsletters
empty: No newsletters yet
limitOptions:
  - 10
  - 25
  - 50

If the folder name is newsletter-archive then you have to find the page by that name:

$newsletters = ($p = $site->find('newsletter-archive') ? $p->children() : new Pages(); // not `newsletter-list`
if ($newsletters->isNotEmpty()) {
  // do stuff
}
1 Like

Thank you very much!
You help me! :slight_smile:

If I didn’t misunderstand you, you could also do:

$newsletters = page('newsletter-archive')->children();

Which might be a bit easier to read.
You may want to add ->listed() to only show the subpages with the status listed.

True, but I’d nevertheless not skip the check if the page exists before calling the children() method.