1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Change breadcrumb current node text to custom text

Change breadcrumb current node text to custom text

9 posts, 0 answered
  1. Roberto
    Roberto avatar
    146 posts
    Registered:
    08 Feb 2008
    22 Feb 2010
    Link to this post
    Hi,

    I am having a problem with the breadcrumb control and overiding the current node text value.  What i have is a sitefinity site that exposes two custom modules which are products and locations.  These form part of the site finity tree by creating a single page and which contain a custom user control to display the details which are obtained via a unique url key for each product and location.

    The problem i am having is for instance the products page crumbs are:

    Home > Products > Product Details

    But i need to somehow output:

    Home > Products > Product A

    Is there a way of achiving this but using any of the standard breadcrumb controls or methods (On Pre Render, On Item Data Bound etc) or am i going to have to create a custom control?

    Thanks

    Rob
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    22 Feb 2010
    Link to this post
    Hi Roberto Modica,

    You could try setting hideUrlServiceNodes property of CmsSiteMapProivder as shown below. By doing so the item url( title) will be authomatically appended as breadcrumb item and you do not have to create a separate page for a single content item.

    <siteMap defaultProvider="CmsSiteMapProvider" enabled="true">
            <providers>
                <clear />
                <add name="CmsSiteMapProvider" hideUrlServiceNodes="false" description="Displays Cms Pages" type="Telerik.Cms.Web.CmsSiteMapProvider" />
            </providers>
        </siteMap>


    All the best,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Roberto
    Roberto avatar
    146 posts
    Registered:
    08 Feb 2008
    22 Feb 2010
    Link to this post
    Hi Ivan,

    thanks for the reply but i am a little confused to how this helps me.  Unfortunantly i dont want to use the page title, i need to use a custom property so i will have to do some work to identify the product name based on the url key.  So for instance i have a product object with a property name, this is the item i wish to use as the current node of the breadcrumb control, i am just having a lot of difficulty figuring out how i can override the last node to insert this text in.

    Thanks,

    Rob
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    22 Feb 2010
    Link to this post
    Hello Roberto Modica,

    The last node should be the current page. You can create a custom class that inherits from Telerik.Cms.Web.UI.Breadcrumb and override InitializeItem method from where you can access each item from the breadcrumb.

    The following sample illustrates how to access the current item

    protected override void InitializeItem(System.Web.UI.WebControls.SiteMapNodeItem item)
      {
          SiteMapNode current = SiteMap.CurrentNode as SiteMapNode;
          SiteMapNode node1 = item.SiteMapNode;
     
          if (current == node1)
          {
               // add your logic here
          }
      }


    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Roberto
    Roberto avatar
    146 posts
    Registered:
    08 Feb 2008
    22 Feb 2010
    Link to this post
    Hi Ivan,

    Thanks for the response i think that is the path i will have to go down and do some checks based on the url (i.e. locations/products etc) do i need to put this in a seperate project and build the dll? or do i simply add this to App_Code and will it override from there?

    Thanks,

    Rob
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    22 Feb 2010
    Link to this post
    Hello Roberto Modica,

    It does not matter whether the code will be in App_Code or compiled into dll.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. Roberto
    Roberto avatar
    146 posts
    Registered:
    08 Feb 2008
    25 Feb 2010
    Link to this post
    Hi Ivan,

    I have sort of got something working but it is not behaving as expected.  For instance if i go into the location Covent Garden then the current node changes from Location Details to Covent Garden if however i go back and then select Manchester  then the current node is still Covent Garden  it is like there is some sort of caching going on as my code looks for Location Details as the hook which is not appearing as the node has been changed to Covent Garden.

    Any ideas, my code is below.

    Thanks,

    Rob

    public class Custombreadcrumb : Breadcrumb
    {
        public Custombreadcrumb()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        protected override void InitializeItem(SiteMapNodeItem item)
        {
            try
            {
                SiteMapNode current = SiteMap.CurrentNode as SiteMapNode;
                SiteMapNode node1 = item.SiteMapNode;
                if (current == node1)
                {
                    string newTitle = current.Title;
                    Context.Response.Write(current.Title);
                    switch (current.Title.ToLower())
                    {
                        case "location details":
                            newTitle = GetLocationName();
                            break;
                        case "product details":
                            newTitle = GetProductName();
                            Context.Response.Write(newTitle);
                            break;
                    }
                    // add your logic here
                    current.Title = newTitle;
                }
            }
            catch (System.NullReferenceException nrex)
            {
                //Do Nothing
            }
            //base.InitializeItem(item);
        }
        private string GetLocationName()
        {
            string key = Context.Request.Params["urlKey"].ToString();
            Location location = Location.GetLocation(key);
            return location.name;            
        }
        private string GetProductName()
        {
            string key = Context.Request.Params["urlKey"].ToString();
            Product product = Product.GetProduct(key);
            return product.name;
        }
    }
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Feb 2010
    Link to this post
    Hi Roberto Modica,

    Does the keys you use the change the title get updated when you switch the pages? It seems that something with GetLocationName() and GetProductName() goes wrong.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  9. Roberto
    Roberto avatar
    146 posts
    Registered:
    08 Feb 2008
    26 Feb 2010
    Link to this post
    Hi Ivan,

    it is not to do with the two methods as url key is something that is required for the url rewrites so that definently changes, the problem is that when i rewrite Location Details to Covent Garden and then change to a different location the current node does not revert back to Location Details it stays as Covent Garden for a small period which means my catch for the term Location Details no longer works untill the system decides to release some sort of cache and makes the current node text Location Details again.

    I have reworked my code so that i have a type parameter on the rewrite url and test if a urlkey is present and if it is use the additional type value to decide which method to work with,  have added the code to help anyone else who may have a similar requirement.

    Rob
    public class Custombreadcrumb : Breadcrumb
      {
          public Custombreadcrumb()
          {
              //
              // TODO: Add constructor logic here
              //
          }
          protected override void InitializeItem(SiteMapNodeItem item)
          {
              try
              {
                  SiteMapNode current = SiteMap.CurrentNode as SiteMapNode;
                  SiteMapNode node1 = item.SiteMapNode;
                  string key = Context.Request.Params["urlKey"] != null ? Context.Request.Params["urlKey"].ToString() : string.Empty;
                  if (current == node1)
                  {
                      string newTitle = current.Title;
                      if (key != string.Empty)
                      {
                          switch (Context.Request.Params["t"].ToString().ToLower())
                          {
                              case "l":
                                  newTitle = GetLocationName(key);
                                  break;
                              case "p":
                                  newTitle = GetProductName(key);
                                  break;
                          }
                      }
                      // add your logic here
                      current.Title = newTitle;
                  }
              }
              catch (System.NullReferenceException nrex)
              {
                  //Do Nothing
              }
              base.InitializeItem(item);
          }
          private string GetLocationName(string key)
          {
              Location location = Location.GetLocation(key);
              return location.name;            
          }
          private string GetProductName(string key)
          {
              Product product = Product.GetProduct(key);
              return product.name;
          }
      }
Register for webinar
9 posts, 0 answered