Created
October 16, 2008 16:50
-
-
Save Oshuma/17196 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/helpers/application_helper.rb | |
# Sets the page title and outputs a container if passed in. | |
# ex. <%= title('Some Page', :h2) %> will return the following: | |
# <h2>Some Page</h2> as well as setting the page title. | |
def title(name, container = nil) | |
@page_title = name | |
content_tag(container, name) if container | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- in your layout file. ex. app/views/layouts/application.html.erb --> | |
<head> | |
<title><%= @page_title || controller.action_name.humanize %></title> | |
</head> | |
<!-- in some view file. ex. index.html.erb --> | |
<!-- note: <%= %> to output a tag --> | |
<%= title('Blawg Home', :h2) %> | |
<!-- which will set @page_title and output an h2 tag, like this: --> | |
<h2>Blawg Home</h2> | |
<!-- or if you don't want to return a content tag, call it like so: --> | |
<% title('Blawg Home') %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment