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.
In a situation similar to yours, I replaced the yield
with a call to content_for
without a block. So in your example it would be simply:
<div data-role="header">
<%= content_for :header %>
</div>
That worked for me. That yield
s in partials don't trickle up as you suggest may be a feature or a bug - but that's still appear to be how it works in Rails 4.1.8, 3 years down the line :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With