Sitefinity Code to Configure Page Title

What we want to achieve?
– To modify the Page Title to “ABC Inc | <Page_Title>” on the fly

How to achieve in Webform Template?
1/ Make sure the HTML Template has included the <title> tag
2/ Add an HTML id to the <title> tag
3/ Webform Template:
Add the title tag with id attribute:

    <head runat="server">
        <title id="page_title"></title>
    <body runat="server">
        <p>Lorem Ipsum</p>

Update page title at Page_Load override method:

protected void Page_Load(object sender, EventArgs e)
    var man = PageManager.GetManager();
    if (SiteMapBase.GetActualCurrentNode() != null)
            var getCurrentPage = SiteMapBase.GetActualCurrentNode().Id;
            if (getCurrentPage != Guid.Empty)
                page_title.Text = page.Title != null ? string.Format("ABC Inc | {0}", page.Title.ToString()) : "ABC Inc | Apple Balloon Crazy";
        catch (Exception ex)
            Log.Write("Template ERROR. " + ex.Message + " " + ex.StackTrace);
            page_title.Text = "ABC Inc | Apple Balloon Crazy";

4/ MVC Widget Virtual Page:
We have some pages are “virtual” page, not the physical page setup in Sitefinity.
Therefore, we need to update the code itself at .cshtml

    var page = (Page)HttpContext.Current.Handler;
    ((System.Web.UI.HtmlControls.HtmlTitle)page.Header.FindControl("page_title")).Text = <your_page_title> != null ? string.Format("ABC Inc | {0}", <your_page_title>) : string.Format("{0}", page.Title);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s