I’m having a problem with the site I’m about to design. My site has 12 menu entries. Would I then also need 12 channels and 12 entries? And: I have only five templates: _header, _main, _footer, 404, and index. Would I need something like an if query to decide what content to display depending on what menu item I click?
P. S.: My home/index template looks like this:
{embed="home/_header"}
{embed="home/_main"}
{embed="home/_footer"}
.
I got a code snippet with an if query (see attachment), but this isn’t working properly, that is, the CSS class ‘nav’ is not being recognized.
Hi Claus
There are two questions here - why is your snippet not working, and what do you need to make menus in EE.
The syntax of your {if}
statement is not correct and so probably EE is getting confused. You should try something like …
<li><a href="http://{path=%27%27}" class="nav{if class == nav && segment_1 == home} active{/if}">Home</a></li>
I’m guessing from your original snippet that there is some kind of variable called class
. Depending on how this value is generated you may need to tweak the if statement to get it to be recognised.
In passing,
these days there are not many situations where using unsecured http connections is a good idea - so might be worth looking at your setup to see if you can use https.
you might be able to use {site_url}
in place of your http://{path=''}
construct.
You can construct menus in a variety of ways in EE, and you certainly don’t need one channel per menu item. Which approach you use depends somewhat upon whether you want to have the ability to control / amend the menu design from within the EE control panel or not.
If you are not planning to modify the menu system from within CP you could simply hard-code the menu design into a template.
If you plan to allow the menu system to be edited from within the CP, you need to decide upon a mechanism for identifying what each menu item should be, and how they are related (e.g. if you plan to do ‘nested’ menus etc).
There are a variety of ways of doing this within EE core features such as using a dedicated channel for the menu items, using EE’s categories system, or using EE’s relationship system.
Alternatively you can use a third-party add-on to build the menu - if you are not so familiar with EE this might be a good option. One example is “Super Navigation” but there are others.
HTH 🐾
Hi,
and many thanks for your suggestions.
> You should try something like …
This worked. Now my menu looks right after all.
> where using unsecured http connections is a good idea …
I have EE installed on a local XAMPP environment with no connection to the internet. When the site is online, there will be https:// of course.
> If you are not planning to modify the menu system from within CP you could simply hard-code the menu design into a template.
CP = control panel, right? The menu is so far a partial. Is this ok?
Claus
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.