Corrects information about subtemplates.

The note about incompatibilities between 2.2 and 2.3 was removed because on Rails 2.2.2, "render :file => 'layouts/application'" works.
This commit is contained in:
Rodrigo Rosenfeld Rosas 2009-02-22 12:13:25 -03:00
parent 247b9563ac
commit 966f86402a

@ -920,14 +920,14 @@ Suppose you have the follow +ApplicationController+ layout:
<erb>
<html>
<head>
<title><%= @page_title %><title>
<% stylesheet_tag 'layout' %>
<title><%= @page_title or 'Page Title' %></title>
<%= stylesheet_link_tag 'layout' %>
<style type="text/css"><%= yield :stylesheets %></style>
<head>
</head>
<body>
<div id="top_menu">Top menu items here</div>
<div id="menu">Menu items here</div>
<div id="main"><%= yield %></div>
<div id="content"><%= yield(:content) or yield %></div>
</body>
</html>
</erb>
@ -941,18 +941,16 @@ On pages generated by +NewsController+, you want to hide the top menu and add a
#top_menu {display: none}
#right_menu {float: right; background-color: yellow; color: black}
<% end -%>
<% content_for :main %>
<% content_for :content do %>
<div id="right_menu">Right menu items here</div>
<%= yield %>
<%= yield(:news_content) or yield %>
<% end -%>
<% render :file => 'layouts/application' %>
</erb>
NOTE: In versions of Rails before Rails 2.3, you should use +render 'layouts/applications'+ instead of +render :file => 'layouts/applications'+
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 'layouts/news'+ to base a new layout on the News layout.
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 :file => 'layouts/news'+ to base a new layout on the News layout. If one is sure she will not subtemplate the +News+ layout, she can ommit the +yield(:news_content) or + part.
h3. Changelog