Dynamic Page Titles

Dynamic Page Titles

Dynamic Page Titles in Sitecore

  • Each page of your site should have a unique title
  • If using .NET Framework 4.0, add the C# code to the code behind file of your site layout (.aspx.cs file)
    • using Sitecore.Web.UI.WebControls;
    • private void Page_Load(object sender, System.EventArgs e)
    • {
    • if (!IsPostBack)
    • {
    • Page.Title= FieldRenderer.Render(item, "menu title");
    • }
    • }
  • For XSLT, add the XSLT code to a file named HtmlPageTitle.xslt and add the following markup to your site layout (.aspx file)
  • 
        
  • <title>         <sc:XslFile ID="Title1" runat="server" Path="/xsl/HtmlPageTitle.xslt" ViewStateMode="Disabled"> </sc:XslFile> </title>

<xsl:value-of select="'TIC - '" />
  <xsl:choose>
    <xsl:when test="sc:fld('title',.)!=''">
      <sc:text field="title" disable-web-editing="true"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="./@name"/>
    </xsl:otherwise>
  </xsl:choose>

Sources