Building Title from Group Path

Building Title from Group Path

Building Title from Group Path

This short tutorial will provide a quick way for you to implement titles on your templates that reflect the names of the group and product. Generally speaking the most specific information should appear at the beginning of the title and then move towards least specific. There are two common mistakes that people make when constructing page titles

  1. All the titles are the same such as "My Company"
  2. All the titles have the same prefix followed by the product such as "My Company XYZ Widget"

When customers bookmark the page the title doesn't have any specific information visible to them instead they just see the same store name over and over again for all their bookmarks. Below is a snippet of code that is good for group pages:

Group Title Tag
#set($title = "")
#set($trailGroups = $formatHelper.reverse($breadcrumbHelper.getBreadcrumbTrail($group)))
#foreach ($trailGroup in $trailGroups)
  #if ($velocityCount > 1)
    #set($title = "$title : ")
  #end
  #set($title = "${title}${trailGroup.getTitle()}")
#end

<title>$title</title>

Let's walk through the logic of this code snippet for the group title tag:

  1. Start out with an empty string for the title variable.
  2. Ask the breadcrumb trail for all the groups from the root group to the current group [$breadcrumbHelper.getBreadcrumbTrail($group))]
  3. Ask the formatHelper to reverse the ordering of the group list [$formatHelper.reverse(...)] and assign this to the variable $trailGroups
  4. Loop through the trailGroups
    1. If this isn't the first group then append a colon to separate the two titles
    2. Add the group title to the title string
  5. Output the title variable inside of the title tags.

On the item page we want similar logic, but want the item description to be in the beginning of the title tag.

Item Title Tag
#set($title = "$item.getDescription()")
#set($trailGroups = $formatHelper.reverse($breadcrumbHelper.getBreadcrumbTrail($group)))
#foreach ($trailGroup in $trailGroups)
  #set($title = "$title : $trailGroup.getTitle()")
#end

<title>$title</title>

Let's walk through the logic of this code snippet for the item title tag:

  1. Start out with the item description assigned to the title variable.
  2. Ask the breadcrumb trail for all the groups from the root group to the current group [$breadcrumbHelper.getBreadcrumbTrail($group))]
  3. Ask the formatHelper to reverse the ordering of the group list [$formatHelper.reverse(...)] and assign this to the variable $trailGroups
  4. Loop through the trailGroups
    1. Add the group title to the title string with a colon in between
  5. Output the title variable inside of the title tags.

Meta Description

You can also use the extended description to build up your meta description tag.

Meta Description
<meta name="description" content="${formatHelper.removeNewLines($formatHelper.removeHtml($item.getDescription()))}"/>