Sam
Sam

Reputation: 462

CakePHP dynamic menu content in layout

What I'm trying to do is to put two dynamic navigation menus in my CakePHP layout (default.ctp). The main menu should have multiple levels (with a dropdown functionality). The secondary menu is the one that shows the dropdown content of the main menu in a left sidebar.

I've read the CakePHP documentation but I'm confused how to fit those menus in the layout. I know that you have 4 different parts in a view layer (as documented in http://book.cakephp.org/2.0/en/views.html):

But with the knowledge I have right now, I think none of this parts can be used to fill my needs. A navigation menu is a part that you only load ONES in a layout, so it isn't an element or a helper. So what's the best practice...

Can anybody clearify my issue? Thanks in advance! ;)

Upvotes: 3

Views: 4533

Answers (1)

Kuldeep Choudhary
Kuldeep Choudhary

Reputation: 775

You can create your menu tree in element folder for example ...

element/top_menu.ctp

element/side_menu.ctp

now you can include these menu in layout as your requirement at dyanamic condition

for example #

if(#user is admin)
{
   echo $this->Element('top_menu');
}
else if(# user is registered)
{
   echo $this->Element('side_menu');
}
else
{
     echo $this->Element('top_menu');
    echo $this->Element('side_menu');
}

Here put your condition ..and you can use menus as your requirements from Elemnts folder......

Upvotes: 2

Related Questions