Jump to content
Stefanowitsch

Get page with a specific template of root parent

Recommended Posts

Hello!

This might be an easy one but I can't figure out the selector. My head is spinning.

I am using the Multisite plugin and want to display custom footer menus based on multiple "submenu" templates.

What I want to achieve:

Get the page with the template "menu_submenus" that is located under the root page of the current page.

My attempt does not work:

$menus = $page->rootParent()->get('template=menu_submenus');

    $footerNav = $menus->footer_menu;

    foreach ($footerNav as $item) { ?>

        <li><a href="<?= $item->url; ?>"><?= $item->title; ?></a></li>

For visualisation heres the page tree:

Bildschirmfoto 2019-07-20 um 11.12.53.png

Share this post


Link to post
Share on other sites

Did you debug it with Tracy?

Check whether you need parent or rootParent, and your template and field names.

Share this post


Link to post
Share on other sites

I got it! Forgot to include HIDDEN pages in the query. Typically my menu templates are hidden pages.

So this is the correct solution:

$page->rootParent()->children('include=hidden')->get('template=menu_submenus');

 

Share this post


Link to post
Share on other sites
13 hours ago, Stefanowitsch said:

So this is the correct solution:


$page->rootParent()->children('include=hidden')->get('template=menu_submenus');

When you do this you load all the children of the of the root parent into memory as a PageArray, and then you get just one of those pages. It's more efficient to directly get the single page you need:

$page->rootParent()->child('template=menu_submenus, include=hidden');

 

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...