More in this section

Forums / Developing with Sitefinity / Change BreadCrumb display to Page Title

Change BreadCrumb display to Page Title

4 posts, 0 answered
  1. Roland
    Roland avatar
    45 posts
    Registered:
    23 Feb 2009
    27 Nov 2009
    Link to this post
    Hi anyone,

    Currently the BreadCrumb displays the name of the page. What if I want to diplay the page Title instead and still be able to retain the correct url?

    How will I be able to accomplish it.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    27 Nov 2009
    Link to this post
    Hello Roland,

    You can create a custom control that inherits from Breadcrumb class and override InitilalizeItem. Then create a new literal there are set the TextProperty to the CmsPage.Title. You do not have to call the base class.

    Sample code:

    protected override void InitializeItem(System.Web.UI.WebControls.SiteMapNodeItem item)
        {
           CmsSiteMapNode currentNode = SiteMap.CurrentNode as CmsSiteMapNode;
           SiteMapNode smNode = SiteMap.CurrentNode;
           smNode.Title = currentNode.CmsPage.Title;
           Literal literal = new Literal();
           literal.Mode = LiteralMode.Encode;
           literal.Text = currentNode.CmsPage.Title;
           item.Controls.Add(literal);
            
        }

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Roland
    Roland avatar
    45 posts
    Registered:
    23 Feb 2009
    30 Nov 2009
    Link to this post
    HI Ivan thanks for the solution it partially solves my problem. However I notice that the initializaitem is being fired more than once and what happens is that the breadcrumb displays the item more than once. What I want to happen is:

    Page Title A > Page Title > AA > Page Title AAA and so on..

    but what happens is:

    Page Title AAA > Page Title AAA > Page Title AAA

    Is there a way to control this one?

    Thanks,
    Roland
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    30 Nov 2009
    Link to this post
    Hi Roland,

    You can modify the InitializeItem method as shown below:

    protected override void InitializeItem(System.Web.UI.WebControls.SiteMapNodeItem item)
       {
           if (item.ItemType == SiteMapNodeItemType.Current)
           {
               CmsSiteMapNode currentNode = SiteMap.CurrentNode as CmsSiteMapNode;
               SiteMapNode smNode = SiteMap.CurrentNode;
     
               smNode.Title = currentNode.CmsPage.Title;
               Literal literal = new Literal();
               literal.Mode = LiteralMode.Encode;
               if (currentNode.Parent != null && currentNode.Parent != SiteMap.RootNode)
               {
                   literal.Text = currentNode.Parent + ">" + currentNode.CmsPage.Title;
     
               }
               else
               {
                   literal.Text = currentNode.CmsPage.Title;
               }
                   item.Controls.Add(literal);
           }
       }


    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
4 posts, 0 answered