Jump to content

SOLVED: PageArray weirdness


Hurme
 Share

Recommended Posts

Edit, solved using Bitpoets suggestio below.

 

Hello,
Lets say I wish to split navigation into primary and secondary navigation in the header area, but then in the mobile navigation I wish to have all the pages visible at the same spot.

I make two new pageArrays, first one includes:

Home, Products, Services

and the second:

Query, Media, Contact

I create the mobile navigation using a yet another pageArray in the simplest way I know:

$mobile_menu = new PageArray();

$homepage = $pages->get(1);
$mobile_menu = $homepage->children;
$mobile_menu = $mobile_menu->prepend($homepage);

// Lets render the whole thing
echo renderNav($mobile_menu);

But instead of spitting out all the pages, it only outputs:

Home, Product, Services

Shouldn't a new pageArray "begin from scratch" instead of inheriting something from another pageArray?
Do I need to do a removeAll after each use of a pageArray or is there some standard way of going about this that doesn't get so messy?

Link to comment
Share on other sites

You want to write that line:

$mobile_menu = $homepage->children;

in one of a few different ways, e.g.:

$mobile_menu->add($homepage->children);
// or, though no need to create a new PageArray beforehand in this case:
$mobile_menu = $homepage->children->makeCopy();

to avoid any caching issues and avoid changing "builtin" PageArrays. If you directly assign $homepage->children, $mobile_menu points to the already loaded instance of the children PageArray of $homepage and your new, empty PageArray gets discarded. Repeated calls to $pages->get(1) are cached and return the page object already in memory. I can only guess since you didn't post that part of the code, but it looks like you may have inadvertently manipulated $homepage->children when you built your main navigation. Make sure to use add() or makeCopy() in that part too.

  • Like 5
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...