I found this great post
<http://blog.55minutes.com/2014/02/easier-nested-layouts-in-rails-34/>
explaining how you can get simple nested layouts in Rails:
# app/helpers/layouts_helper.rb
> module LayoutsHelper
> def parent_layout(layout)
> @view_flow.set(:layout, output_buffer)
> output = render(:file => "layouts/#{layout}")
> self.output_buffer = ActionView::OutputBuffer.new(output)
> end
> end
> # app/views/layouts/base.html.erb
> <!DOCTYPE html>
> <html>
> <head>
> </head>
> <body>
> <%= yield %>
> </body>
> </html>
> # app/views/layouts/application.html.erb
> <div class="container">
> <%= yield %>
> </div>
> <% parent_layout "base" %>
You will end up with
<!DOCTYPE html>
> <html>
> <head>
> </head>
> <body>
> <div class="container">
> <%= yield %>
> </div>
> </body>
> </html>
Now, this works with ERB. But when I change the application.html.erb to
application.html.haml, the outer layout (base) is not rendered anymore.
I tried to use `@haml_buffer` instead of `self.output_buffer` in the
`LayoutsHelper` but couldn't get it to work.
Here is a repo with a vanilla Rails 4.1.1 app implementing this:
https://github.com/krautcomputing/nested-layout-test
Can anyone help me to get this to work?
What do I need to change in the `LayoutsHelper`?
Thanks a lot!
--
You received this message because you are subscribed to the Google Groups
"Haml" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/haml.
For more options, visit https://groups.google.com/d/optout.