Feed on
Posts
Comments

In the PlanningAlerts project, we recently added a default page title for those pages we forget to add specific titles to. I added the initial code and Matthew did it properly cleaned it up, here’s the diff:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
diff --git a/app/views/layouts/application.haml b/app/views/layouts/application.haml
index 27d81d9..6b42b26 100644
--- a/app/views/layouts/application.haml
+++ b/app/views/layouts/application.haml
@@ -2,10 +2,7 @@
 %html(xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml")
   %head
     %meta(content="text/html; charset=utf-8" http-equiv="Content-Type")
-    - if @page_title
-      %title PlanningAlerts | #{@page_title}
-    - else
-      %title PlanningAlerts | Email alerts of planning applications near you
+    %title PlanningAlerts | #{@page_title || "Email alerts of planning applications near you"}
     - if @rss
       %link(rel="alternate" type="application/rss+xml" title="RSS" href=@rss)
     = stylesheet_link_tag "memespring", "main", :media => "all"

I thought other people might find this little hack useful for adding default page titles to their HAML templated Ruby on Rails projects.

2 Responses to “Add a default page title with HAML in Rails”

  1. erietta says:

    I am no coder, but its a good seo move. Title is an important property.

Leave a Reply