Display page titile by fetching the page model name "mentions"

Hi,

I want to display the page title of my pages “mentions légales” and “nous rejoindre” to create au 2nd menu. The page model of theese pages is “Mentions”.

Now I display all the pages invisible, but how can I specifying the page I want display ?
There is how they are in the panel

and this how I tryed to display only this page

<?php foreach ($pages->invisible() as $menu): ?>
  <li>
    <a <?php e($menu->isOpen(), 'class="active') ?> href="<?php echo $menu->url() ?>" title="<?php echo $menu->title() ?>">
      <?php echo $menu->title() ?>
    </a>
  </li>
  <?php endforeach ?>

thanks

I’d use the pages directly:

$menupages = $site->find('mentions-legales', 'nous-rejoindre');
foreach($menupages as $menulink):
// code
endforeach;

If they share the same blueprint, you can also filter by intendedTemplate()

$menupages = $pages->findBy('intendedTemplate', 'blueprint-name');

Another way that i do sometimes is to use a toggle field on every page so i can turn it on or off in the menu regardless of its visibility. Good if you want to give clients control of what appears in the menu.

  <?php foreach ($site->pages() as $menu): ?>
    <?php if ($menu->featureinnav()->bool()): ?>
    <li>
    <a <?php e($menu->isOpen(), 'class="active') ?> href="<?php echo $menu->url() ?>" title="<?php echo $menu->title() ?>">
      <?php echo $menu->title() ?>
    </a>
    </li>
    <?php endif ?>
  <?php endforeach ?>

And another option would be to create the menu in the site options using a structure field with a page subfield. This gives you the option to add pages as required and also to sort them manually if necessary.

@jimbobrjames You can filter by whether or not that field is true, then you don’t need the if statement.

$site->pages()->filterBy('featureinnav', true);
1 Like