Render content in layout
I came up with a hack to render content inside a layout, from the controller:
1 2 3 4 5 6 7 8 9 10 |
def content_with_layout(content_for_layout, controller, layout = "the_layout") locals = { :params => controller.params } template = controller.class.view_class.new(controller.class.view_root, locals, controller) template.instance_variable_set("@content_for_layout", content_for_layout) # This might work to get assigns? untested... #template.assigns = controller.template.instance_variable_get("@assigns") template.render_file("layouts/#{layout}", true) end |
You have to pass in any locals you want, and if you want the use assigns in your layout you would have to set the template.assigns. There was some plugin to give you extra layouts in the view but I forget what it was called. Anybody know where that is?
Update: The inside layout is at: http://fora.pragprog.com/rails-recipes/write-your-own/post/144
Tags: rails