Jump to content

Custom menu


Nelson
 Share

Recommended Posts

Hello everyone,

I'm trying to make a custom menu where I need to create a placeholder (drop down) for specific pages but I would like to make this dynamic, so I wouldn't need to edit the navigation file everytime there's a change.

Basically something like this:

Home

Page A

Page B

Page C

Page D

Page E

Page F

Page G

To this:

Home

Page A

Page B

Placeholder (not a real page)

|----Page C

|----Page D

|----Page E

|----Page F

Page G

I can acces the specific pages through a hidden field, I check for its existence.

I know it's possible to create a new Page dynamically but can you add children to it without saving it?

I could go for recursion but then almost every other page has children but I don't need them to show up in the menu.

I may be complicating something but I don't know, so any help is welcomed!

Thank you.

Link to comment
Share on other sites

I'm not sure I understand why you want to create it on the fly, though I think you could. Why don't you just create the structure of the "Placeholder" with it's subpages? It will be not so easy to do what you explain.

You could create a special placeholder page where you want with whatever template, then move the Pages C,D,E,F inside it.

Then you could show the second level there only if the parent is the placeholder page.

Using my MarkupSimpleNavigation you would do this using the custom selector setting:

$nav = $modules->get("MarkupSimpleNavigation")->render( array(
   'show_root' => true, // include home (root page)
   'max_levels' => 2, // limit to 2 levels
   'selector' => 'parent=/|has_parent=1004' // *.
 ));
echo $nav;

*

This selector makes it show all pages that have "/" (root home page) as direct parent,

OR pages that have the "placeholder" page (id or path of page page) as their parent. You could also write has_parent=/pathofpage/.

("parent=/|parent=1004" doesn't work for some reason.)

Link to comment
Share on other sites

Thanks Diogo and Soma for your replies.

The reason I want to do this on the fly it's because I don't wanna add another level of navigation in the backend to pages that already have 2 sub-levels inside. It's for the sake of simplicity for the users that are going to manage the site, those pages need to be immediately visible and accessible.

Unless there's a way to keep the placeholder always open in the backend.

Thank you.

Edit: I've done it! It's not the most beautiful code and I think it can be improved but for now does the job. I can share if anyone's interested.

Basically I extract the pages I need from the list, store them in array, then inject them back in the list. In the building function I do a check for type and if it's a array it builds another level.

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

×
×
  • Create New...