cakephpcakephp-2.xcakephp-2.7

Separate navigation menu from default.ctp in CakePHP


I am working on CakePHP 2.7. I have to show some static menu on every page. Since, the menu contains lot of sub menus, I want to keep them in a separate file navigation.ctp and show them on default.ctp

I tried extend and elements but none of them give expected result.

Note : This is not dynamic menu and I am not fetching them from database.


Solution

  • Place your navigation.ctp inside app/View/Elements/

    Then, inside your default.ctp, include the element as follows:

    <?= $this->element('navigation'); ?>
    

    Note that if you need any variables within the element, you may need to pass them through inside an array as a second parameter, such as:

    <?= $this->element('navigation', array(
        "varible_name" => "variable_value"
        )); ?>