Kirby

Page with "partners" template is shown with "default" filter (3.2.0-rc.2)

I was trying to show only those pages in menu, that belong to certain templates:

$items = $site->pages()->filterBy('template', 'in', ['about','landing','default'])->listed();

Filters are working fine, but only ‘default’ is showing Partners parent page and Partners children. I think the first reason was, that I left template name “default” in Partners and Partners blueprints. But although I changed it now, also tried to delete parent page of Partner and children, and created them again, but it’s still displayed with ‘default’ filter. What can be the reason?

Here is full code for menu:

<?php

// nested menu
$items = $site->pages()->filterBy('template', 'in', ['about','landing','default'])->listed();

// only show the menu if items are available
if($items->isNotEmpty()):

?>



  <ul class="navbar-nav mr-auto">
    <?php foreach($items as $item): ?>
    <li class="nav-item <?php e($item->isOpen(), 'active') ?> <?php if($item->children()->listed()->isNotEmpty()): ?>dropdown<? endif ?>
 ">
 
 <?php if($item->children()->listed()->isEmpty()): ?>
      <a class="nav-link" href="<?= $item->url() ?>"><?= $item->title()->html() ?></a>
 <? endif ?>

 <?php if($item->children()->listed()->isNotEmpty()): ?>
      <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?= $item->title()->html() ?></a>
 <? endif ?>

      <?php

      // get all children for the current menu item
      $children = $item->children()->listed();

      // display the submenu if children are available
      if($children->isNotEmpty()):

      ?>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <?php foreach($children as $child): ?>
        <a class="dropdown-item <?php e($child->isOpen(), 'active') ?>" href="<?= $child->url() ?>"><?= $child->title()->html() ?></a>
        <?php endforeach ?>
      </div>
      <?php endif ?>

    </li>
    <?php endforeach ?>
  </ul>

<?php endif ?>

Does the partners template exists? Kirby uses the default template for all pages that don’t have a dedicated template.

In cases like that it makes more sense to use intendedTemplate() instead of template().

1 Like

intendedTemplate() - this helped, thank you!

As far as I understand, partners template exists.

it exists if both blueprint and a template file exist afaik.

The blueprint is only necessary in this context if you create your pages via the Panel, so that you get the correct content file name. intendedTemplate() is the template as defined by the content file name. E.g. if the content file is called whatever.txt, the intended template is whatever.php, no matter if there is a file called whatever.php in /site/templates or not. filterBy('template', 'whatever') will only work if the file/site/templates/whatever.php` really exists.