diff options
-rw-r--r-- | railties/guides/source/layouts_and_rendering.textile | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile index 3d27b52e41..d9bc605b84 100644 --- a/railties/guides/source/layouts_and_rendering.textile +++ b/railties/guides/source/layouts_and_rendering.textile @@ -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 |