ruby-on-railslayoutpartialscontent-for

rails partial's layouts with named yield - why is yield block never used?


I have a partial, with a layout:

<%= render :partial => 'home/mobile/home', :layout => 'home/mobile/page', :locals => {:page => 'abc2'}%>

The layout (page.html.erb) has yields for different blocks, such as:

<div data-role="header">
  <%= yield :header %>
</div>

However, this yield block is never used, while the main-level layout file does yield as one would expect.

Is it impossible to use named content_for/yield blocks with the layouts of partials? Are there workarounds?

I would expect inheritance-- content_for :header should first look for a yield :header in the partial's layout, and failing that, the main layout file. But this is not the case. The partial layout's yield :header is simply ignored.


Solution

  • The workaround would be to wrap your layout into an helper method using blocks (which should be able to yield correctly).

    You may want to fil a bug about the original problem.