Create a gist now

Instantly share code, notes, and snippets.

Nice nested layouts -- this does what *I* expect, at least.
= inside_layout :application do
%section.admin
%header ...
= yield
%footer
class AdminController < ApplicationController
layout :admin
def index
render :dashboard
end
end
!!!
%html
%head ...
%body
%header ...
= yield
%footer ...
%h1 Dashboard
...
module NestedLayoutsHelper
# Wrap some content inside a layout
def inside_layout(layout, &block)
layout = layout.to_s
layout = layout.include?('/') ? layout : "layouts/#{layout}"
controller.render_to_body(:layout => layout, :text => capture { block.call(@_content_for[:layout]) })
end
end
@zealoushacker

Thanks for this good work! Have you seen this one? https://gist.github.com/907555

What are your thoughts on advantages and disadvantages?

Best,
Alex

@sj26
Owner
sj26 commented Jul 24, 2011

I use a custom branch of justinfrench's nestive these days: https://github.com/sj26/nestive

I like the default to "application" for layout, but it doesn't take rending inside templates outside the layouts directory into account. It also double-renders the HAML output as ERB. render :inline => ... will render the provided content as ERB, not just place it inside the layout, it should use :text. It also won't do nested layouts within nested layouts unless you use content_for[:layout]. I probably should have put that block capture a line above to make it clear that the capture happens before the render, which is important.

Check out the aforementioned branch, it handles all these cases and has nestive's excellent areas.

@zealoushacker

Thanks for the response!

Looking at your fork: https://github.com/sj26/nestive/commits/master

So does your fork support HAML, but justinfrench's does not?

@sj26
Owner
sj26 commented Jul 24, 2011

No, nestive is template-engine agnostic.

Originally, nestive requires you to declare layout nil in your controllers and then use extends in every template. I modified it so layout "application" works as expected, with nested templating and areas available throughout.

@rwz
rwz commented Aug 22, 2011

capture { block.call(@_content_for[:layout]) }) should to be changed to capture { block.call(content_for :layout) })

at least it worked for me in 3.1.0.rc6

@sj26
Owner
sj26 commented Aug 22, 2011

@rwz, please use nestive. It does the same thing but better. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment