how to do multi level layout

* A site has the default global layout and navigation links.
* Within the site, it has several different sections,
* each section has many pages, which has same sub nav links and some
common parts.

* how do i wrap a section page with section layout first, and then
global layout?
* what's the best way to handle such multi level layout situation?

Two solutions I tried, and I don't like either one.
1. create a layout for each section, the layout duplicate global
layout elements
2. only use global layout, then render partial section_header,
section_footer on every single page.



but a "global.rhtml" layout,
which calls "render :partial => "section_links""

would render "_section_links.rhtml"
in the appropriate directory.

so in the users controller it'll render /users/_section_links.rhtml
and in the product controller it does /product/_section_links.rhtml.

maybe that's what you want.

This will work if all sections are very similar, and require every
section to have section_links.rhtml, which should be ok in most

through trial and error, i found out this setup is more flexible. To
use namespace in layout file, and rename layout as partial.
so I copy layouts/application.rhtml to shared/layouts/

======== shared/layouts/_application.rhtml =============
<%= render(:partial => "/shared/global_header") %>
<div id="section_header"><%= yield "top" %></div>

<div id="main"><%= yield %></div>

<%= render(:partial => "/shared/global_footer") %>

======== layouts/product.rhtml =============
<% content_for :top do %>
  product_home | hardware | software | ...
<% end %>

<%= render(:partial => "/shared/layouts/application") %>

======== layouts/support.rhtml =============
<%= render(:partial => "/shared/layouts/application") %>

Product section wants a section navbar on top, so it just do that in
the product layout, for ProductController
Support section don't need navbar, so it just skips it.

one drawback, namespaced part can not be cached.


I hope my question is consistant with your thread. I have a VERY large
application with all kinds of sub-applications such as forums, diggs,
blogs, etc. and wish to split up the \application\app metaphor to be
\application\app\subprogram. Has anyone done this?
I see following your thread how you'd handle calling views, but what
about models and controllers?
I am grateful for any reply.

This PDF from a rails conf presentation has some interesting ideas:

I ran into a similar problem and came across the following discussion
about "nested layouts" which provides some good insight into the

it seems there's also a nested-layout plugin available which I haven't
had any experience with..


Some good ideas in this presentation but if I understand the OP's
question, it's about having multiple tiers of layout. Sort of like
(tags omitted for brevity):

<!-- layout.erb -->
<!-- xhtml'ey stuff -->
<%= render :partial => yield :section_layout %>

<!-- _my_section_layout.erb -->
Hi! Welcome to the chunky bacon section
<%= yield :layout %>
goodbye to the chunky bacon section

<!-- my_view.erb -->
<% content_for :section_layout do %>my_section_layout<% end %>
   Other stuff specific to the particular view. Note that the section
layout can also be set in the controller using

I'm not positive this works, and you might have to "help" Rails
understand the search path for the section layouts, but it's worth a

perhaps I'm misunderstanding but why not this: