README.md

Nestive

A Nested Inheritable Layouts Plugin for Rails

Nestive adds powerful layout and view helpers to your Rails app. It's similar to the nested layout technique already documented in the Rails guides and found in many other nested layout plugins (a technique using content_for and rendering the parent layout at the end of the child layout). There's a bunch of problems with this technique, including:

you can only append content to the content buffer with content_for (you can't prepend to content, you can't replace it)

when combined with this nested layout technique, content_for actually prepends new content to the buffer, because each parent layout is rendered after it's child

Nestive is better because it addresses these problems.

Just five methods (so far) – area, extends, append, prepend, replace.

Declaring an area of content in your parent layout with area:

The area helper is a lot like Rails' own <%= yield :foo %>, and is used in layouts to define and render a chunk of content in your layout:

<%= area :sidebar%>

Unlike yield, area will allow your parent layouts to add content to the area at the same time using either a String or a block:

It's important to note that this isn't default content, it is the content (unless a child changes it).

Appending content to an area:

The implementation details are quite different, but the append helper works much like Rails' built-in content_for. It will work with either a String or block, adding the new content onto the end of any content previously provided by parent layouts: