Stefanowitsch Posted July 20, 2019 Posted July 20, 2019 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:
dragan Posted July 20, 2019 Posted July 20, 2019 Did you debug it with Tracy? Check whether you need parent or rootParent, and your template and field names.
Stefanowitsch Posted July 20, 2019 Author Posted July 20, 2019 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');
Robin S Posted July 21, 2019 Posted July 21, 2019 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'); 1
Stefanowitsch Posted July 21, 2019 Author Posted July 21, 2019 Cool! That's even better. I will use that.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now