Hi, does Rails support nested layouts? For example you could have an
application level layout that contains the head tags and so on, a nested
layout for the ‘magazine section’ containing the navbar and a certain
CSS, then the content nested into that.
As you move between sections you keep the same ‘top level’ layout file
(the one with the head tags, meta, etc, but switch the ‘internal’
layout.
So far I’ve only heard of the possibility of ‘one layout’, and some
nested content.
You can use partials to reuse chunks of html across different layouts.
For example, in your layouts directory could be setup like this:
/layouts/_meta.rhtml
/layouts/_nav.rhtml
/layouts/_footer.rhtml
/layouts/layout1.rhtml
/layouts/layout2.rhtml
/layouts/layout3.rhtml
In each of the three layout files, you’d include each of the partials
in their appropriate location in the page. e.g. to include the meta
info, you’d use <% render :partial => ‘/layouts/meta’ %>
To specify which layout you’re using in a given controller, just use
layout ‘layout2’
at the top of your controller.
Hope this helps.
There is a plugin that adds support for nested layouts:
http://nested-layouts.rubyforge.org/