Last Updated: September 09, 2019
·
915
· kaiuhl

Helper for page titles and descriptions

module ApplicationHelper
  # Helper to display titles and descriptions.
  # Used in views and the layout.
  #
  # in a layout file:
  #
  #   <title><%= page :title %></title>
  #   <meta name="description" value="<%= page :description %>" />
  #
  # and in a view file:
  #
  #   <% page :title, "Awesome Title!" %>
  #   <% page :description, "Meta Description of the Gods." %>
  #
  def page(sym, t = nil)
    return content_for(sym) { t } unless t.nil?
    content_for?(sym) ? content_for(sym) : "Untitled"
  end
end