Nice nested layouts »
I really wanted a nicer way of doing nested layouts using HAML in Rails. The rails example including yield(:content) || yield makes me want to heave. Okay, so they use content_for? now, but it’s still horrid, and what happens when you’re more than one or two levels deep?
Ideally, layouts should be able to dictate they inherit from something else. Partially inspired by the NestedLayouts plugin for Rails 2, the best way to do this I could come up is to use a capture block in my layout. This means I can use:
Inside my application layout:
and now use layout :admin in my admin controllers:
and it will nest nicely as expected.
The helper itself looks like:
and these extracts are all part of this gist.
I hope you find it useful too. Have fun!