A layout page basically defines the main HTML page into which your dynamic content will be inserted. It provides two basic services: stops you having to repeatedly enter standard HTML header and basic formatting on every page; and gives you a single framework to define your page styles so that they are consistent across multiple pages.
The content of the layout page is wrapped around your standard view pages and this is done before the page is sent to the web server. So as far as your browser is concerned, it receives a single page - no frames.
However, that doesn't mean you can't have dynamic content. For example look at this layout:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>My Site : <%= @page_title || controller.controller_name.capitalize + " (" + controller.action_name + ")" -%></title>
<%= stylesheet_link_tag 'a_style_sheet' %>
<%= javascript_include_tag :defaults %>
</head>
<body>
<h1><%= @page_title -%></h1>
<div id="flash_notice"><p><%= flash[:notice] %></p></div>
<div id="main_content"><%= @content_for_layout %></div>
<div id="footer"><%= render(:partial => "shared/footer") %></div>
</body>
</html>
Standard HTML header information is defined in this one place. For example, the DOCTYPE declaration only has to be made once.
However, Rails dynamic tools are still available - so that in this example, the page title has been constructed dynamically (either from @page_title that can be defined at the controller or view, or from the controller and action names)
The layout can include locations for standard Rails output, like flash[:notice].
By locating standard output such as @content_for_layout (does the same as yield in your example) within div tags in the layout, each section can be easily controlled and located via CSS. So you can get a frame type appearance and behaviour via CSS div blocks.
For your specific problem notice how this example also includes a footer partial. The content displayed here will be defined within view file : shared/_footer.rhtml. This will give you your single location for footer information that will appear on every page that uses this layout. You can add as many of these as you like - so perhaps a navigation partial at the top of the page (between flash_notice and main_content for example).
Bookmarks