Nested Layouts

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’

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:


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: