-
Notifications
You must be signed in to change notification settings - Fork 0
Rendering
The main method to render your navigation in the view is render_navigation. You can pass the following main options to render_navigation:
- :level – this option determines which parts of your navigation are rendered with this render_navigation call. Use :level => :all to render all your levels at once. Use :level => 1 to render just the first level of your navigation. Use :level => 1..2 to render the first two levels of your navigation. Defaults to :all. See the code examples below for details.
- :expand_all – Set :expand_all => true to render your navigation as a fully expanded tree. This is useful for javascript style menus like Superfish. Defaults to false.
The following examples show how to use render_navigation.
Call
render_navigation
without any parameter to render all defined levels of navigation nested into each other (like a tree). By default, only the sub navigations of active parent items are rendered (see the section about how to set the active item above). If you want to render all the sub navigations at once (i.e. a fully expanded navigation tree – useful for javascript menus) you have to pass the option :expand_all => true.
If you have to render your sub navigation independently from the navigation containing it (e.g. you render your primary navigation horizontally on the top of the page and the sub navigation vertically on the left of the page in a sidebar), then you specify the level when calling render_navigation
render_navigation(:level => 1)
This renders your primary navigation (‘Books’, ‘Music’, ‘Dvds’). To render the sub navigation, call
render_navigation(:level => 2)
This renders the current sub navigation (i.e. ‘Fiction’, ‘History’, ‘Sports’ if the ‘Books’ primary navigation item is active).
If you have more than two levels, you can also specify ranges. For example, let’s consider the following setup:
You have a navigation with three levels. The first two levels should be rendered as a navbar-style javascript menu using superfish. The third level should be rendered separately in a sidebar. To achieve this you would have the following code in your view (using HAML):
#top_navigation= render_navigation(:level => 1..2, :expand_all => true)
#sidebar= render_navigation(:level => 3)
:javascript
$(document).ready(function(){
$("#top_navigation ul").superfish();
});