Subnav

A useful little snippet for producing a sidebar subnav:

<div class="subnav">
  <h4><%= @page.line.first.title %></h4>
  <ul>
    <% @page.line.first.children.each do |page| %>
      <%= render_page_in_hierarchy(page) { |p| 
        if p.line.size <= 3
          if (p == @page) 
            link_to_page(p.title, p, {}, {:class => "active"})
          else
            link_to_page(p.title, p)
          end
        end
      } %>
    <% end %>
  </ul>
</div>

The key bit of usefulness here is that you can specify the depth of your subnav by changing the value you're comparing with page.line.size. In this example, you'll show subnav down to three levels, but you can adjust that however you like. It also applies a class of 'active' to the current page.

User notes

(You can add notes to this page using the form below.)


Only the note field is required.

Preview or