Skip to content

Commit

Permalink
Fixed mistakes in layouts/rendering guide about yield
Browse files Browse the repository at this point in the history
yield(:unspecified_block) actually returns true even if :unspecified_block never
exists. This means you can't use the form yield(:unspecified_block) or yield.
  • Loading branch information
jem committed Aug 15, 2011
1 parent f7626ea commit 583d7c1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions railties/guides/source/layouts_and_rendering.textile
Expand Up @@ -1179,14 +1179,14 @@ On pages generated by +NewsController+, you want to hide the top menu and add a
<% end %> <% end %>
<% content_for :content do %> <% content_for :content do %>
<div id="right_menu">Right menu items here</div> <div id="right_menu">Right menu items here</div>
<%= yield(:news_content) or yield %> <%= content_for?(:news_content) ? yield(:news_content) : yield %>
<% end %> <% end %>
<%= render :template => 'layouts/application' %> <%= render :template => 'layouts/application' %>
</erb> </erb>


That's it. The News views will use the new layout, hiding the top menu and adding a new right menu inside the "content" div. That's it. The News views will use the new layout, hiding the top menu and adding a new right menu inside the "content" div.


There are several ways of getting similar results with different sub-templating schemes using this technique. Note that there is no limit in nesting levels. One can use the +ActionView::render+ method via +render :template => 'layouts/news'+ to base a new layout on the News layout. If you are sure you will not subtemplate the +News+ layout, you can replace the +yield(:news_content) or yield+ with simply +yield+. There are several ways of getting similar results with different sub-templating schemes using this technique. Note that there is no limit in nesting levels. One can use the +ActionView::render+ method via +render :template => 'layouts/news'+ to base a new layout on the News layout. If you are sure you will not subtemplate the +News+ layout, you can replace the +content_for?(:news_content) ? yield(:news_content) : yield+ with simply +yield+.


h3. Changelog h3. Changelog


Expand Down

0 comments on commit 583d7c1

Please sign in to comment.