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

Forums / Designing with Sitefinity / Hide breadcrumb when showing one level

Hide breadcrumb when showing one level

3 posts, 1 answered
  1. olav
    olav avatar
    76 posts
    Registered:
    22 Jan 2007
    15 Sep 2009
    Link to this post
    Hi,

    I have the Sitefinity breadcrumb control in some templates, using these settings:
    ShowStartingNode = False
    ParentLevelsDisplayed = -1
    RenderCurrentNodeAsLink = False

    The second level pages display themselves only (single level) in the breadcrumb, which is kind of needless and a bit confusing for the users.

    I could of course deal with this using separate templates, but please tell me if I have missed an obvius setting somewhere. A HideIfOneLevel property would be nice..

    I'm new to developing with Sitefinity, but I guess there's some solution in writing code. (I'm currently using such solutions in other VS projects)
    In case it is hard to keep such code simple and tidy, the template copy solution would be preferred.

    Anyway, comments and suggestions would be great.

    -olav
  2. Nikolai
    Nikolai avatar
    216 posts
    Registered:
    21 Nov 2016
    15 Sep 2009
    Link to this post
    Hello olav,

    Unfortunately this functionality is not covered by the current BreadCrumb control but is very easily achievable by overriding it like this:

    1. Create a class called BrCrumbClass(for example) inside App_Code folder.

    This new class should inherit  Telerik.Cms.Web.UI.Breadcrumb and you will need to just override the InitializeItem method and add one additional property HideIfParentIsOne(for example):

    namespace BreadCrumbNameSpace 
        public class BrCrumbClass: Telerik.Cms.Web.UI.Breadcrumb 
        { 
            [System.ComponentModel.DefaultValueAttribute(false)] 
            [System.ComponentModel.CategoryAttribute(@"Behavior")] 
            public bool HideIfParentIsOne{getset;} 
         
            protected override void InitializeItem(System.Web.UI.WebControls.SiteMapNodeItem item) 
            {          
                base.InitializeItem(item); 
     
                if (SiteMap.CurrentNode.ParentNode == SiteMap.RootNode && HideIfParentIsOne) 
                { 
                    this.Visible = false
                }                       
            }         
        } 

    2. Inside the InitializeItem method check the new property value and state of the current SiteMap node parent.

    3. Here is how to add the new BreadCrumb control to the ToolBox inside Sitefinity page editor.

    Inside the web.config file go to  <toolboxControls> section and add this line:

      <add name="BrCode" section="Misc" type="BreadCrumbNameSpace.BrCrumbClass, App_Code" /> 

    Hope this helps.

    Greetings,
    Nikolai
    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.
    Answered
  3. olav
    olav avatar
    76 posts
    Registered:
    22 Jan 2007
    15 Sep 2009
    Link to this post
    Thanks a lot!
    Nice to discover the flexibility of Sitefinity.

    I just needed to modify your code with some simple error handling so that the page does not generate an error when clicked in the Sitefinity sitemap. (object not set)

    -olav
Register for webinar
3 posts, 1 answered