Jump to content

[SOLVED] How can I dynamically generate a menu with a placeholder entry?


Boost
 Share

Recommended Posts

Hei,

I hope I'm not overcomplicating things here, but I can't figure out how to generate my menu using the ukNav***() functions from the default site profile in _uikit.php. The issue lies with my "Resources" entry, which is merely a placeholder and doesn't exist in the system. Here's the layout of my menu:

Why Acme      Product     Solutions     Resources       Contact
               -product1   -solution1    -blog
               -product2   -solution2    -case studies
               -product3                 -guides

Everything here is a page, except for the "Resources" entry. So, is there a way I can generate the menu automatically?

Yes, I could simply "hard code" it, and I have done that. However, I can't find a way to apply the uk-active class to the current element.

Any assistance would be greatly appreciated!

Cheers!

Link to comment
Share on other sites

You have to give more context to get proper answers I guess. If "Resources" is not a page, where do pages like /resources/blog etc. really live? Where are they stored? If they are stored somewhere else, why do you want to show them in the menu under "resources"? If you want to show them under "resources", why don't you just create a page "resources" and store them as child?

So maybe you are overcomplicating things. But I guess nobody can tell as long as you are oversimplifying your answer ?? 

Link to comment
Share on other sites

There are many possible solutions for making urls shorter. In your case you could for example just name the "resources" page "r" then you'd get urls like example.com/r/blog/your-blogpost

This thread should be an interesting read for you:

Another solution could be a module for creating decoupled menus, like https://processwire.com/modules/process-menu-builder/ . There might be more such modules, though I have to say I have never used one of them and also keep in mind what Ryan has to say about it in the linked thread:

Quote

WillyC's solution is a good way to go if you have this need. But want to mention that the whole idea of multiple routes to a page kind of goes against the grain of the ProcessWire philosophy. By design, there is only one URL to any given page. This is different from systems that disconnect their data from URLs (Drupal, EE, etc.). ProcessWire considers pages like files on a file system. We are trying to embrace the way that the web is addressed rather than counter it.

I understand the desire to make a shorter URL for a given page, and that's a fine reason to implement a solution like this (and I've done it myself too). But the reason you don't see things like this outlined in the documentation is because I don't think it's a best practice, whether in ProcessWire or on the web in general. So if someone uses multiple routes, I would suggest it only to solve a specific need after a site is produced… not as something to build around from the start.

 

  • Like 1
Link to comment
Share on other sites

  • Boost changed the title to [SOLVED] How can I dynamically generate a menu with a placeholder entry?
  • 2 weeks later...

I would perhaps do it something like this:

Create a page called "siteSettings" or something similar. Good place to keep things like website logo and other global stuff.

Add page reference field that can have multiple pages and can be rearranged. Lets call it "navPages".

Select pages in it you want to use in your navigations top level.

For Resources page, create a page that has the same navPages field in it, and in this field you can choose the blog, case studies and so forth. Resources page doesn't need template file because it will never be visible in the frontend. Add Resources page into the siteSettings->navPages field.

You'll need to write a function to render out siteSettings->navPages as the navigation.

Write the logic so that for Resources page (and others using the same template) will build the drop down but wont actually create a link to the non-existing page.

This will also let you easily add "uk-active" or similar in the navigation, because there is an actualy relation between Resources and Blog as an example.

The logic in the foreach loop could be something like:
 

if($page->children() || $page->navPages) {
	// Keep adding levels to the navigation
}

 

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...