Skip to content

Instantly share code, notes, and snippets.

@sj26
Created April 9, 2011 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sj26/911446 to your computer and use it in GitHub Desktop.
Save sj26/911446 to your computer and use it in GitHub Desktop.
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 ...
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
@rwz
Copy link

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
Copy link
Author

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