1. Patrick Byrne
  2. Dynamic Page Title


Set the page title with:
    <% title "This is the page title" %>

Get the page title with:
    <%= page_title %>
    # will output <title>This is the page title</title>

It also accepts an options hash to change the tag it uses (e.g., to a heading tag to be visible on the page), appending or prepending text, or passing HTML options to the resulting tag (e.g., anything accepted as HTML options by a content_tag):
    <%= page_title(:tag => :h1) %>
    # will output <h1>This is the page title</h1>
    <%= page_title(:append_text => " - Example.com") %>
    # will output <title>This is the page title - Example.com</title>
    <%= page_title(:prepend_text => " is what you are viewing") %>
    # will output <title>This is the page title is what you are viewing</title>
    <%= page_title(:html_options => {:lang => "en"}) %>
    # will output <title lang="en">This is the page title</title>