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

Forums / Developing with Sitefinity / customizing sitepanelbar

customizing sitepanelbar

17 posts, 0 answered
  1. Satya Vepa
    Satya Vepa avatar
    31 posts
    Registered:
    03 Dec 2009
    22 Jan 2010
    Link to this post

    Hi,

     

    Is it possible to configure sitepanelbar to display current nodes parent menu to display , when there are no items under current node.

     

    ex:

    Item1

       SubItem1

            SubSubItem1      
            SubSubItem2
            SubSubItem3
       SubItem2

       SubItems

    On Clicking SubSubItem1, as there are no menu items under that , the panel should display
    SubItem1
    SubItem2
    SubItem3

    Thanks
    Satya
    I am using Sitefinity 3.7 and using the built in skins and css.

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    25 Jan 2010
    Link to this post
    Hi Satya Vepa,

    Here is a sample code that you can add OnPreRender of the SiteMenu control to get the desired functionality working

    CmsSiteMapNode item1 = SiteMap.CurrentNode as CmsSiteMapNode;
      if (item1 != null)
      {
          if (item1.ChildNodes.Count == 0 && item1.ParentNode != SiteMap.RootNode)
          {
              CmsSiteMapNode parent = item1.ParentNode as CmsSiteMapNode;
              foreach (CmsSiteMapNode parentNode in parent.ChildNodes)
              {
     
                  RadPanelItem rootitem = RadPanelbar1.FindItemByText(item1.Title);
                  if (rootitem != null)
                  {
                      RadPanelItem panelitem = new RadPanelItem(parentNode.Title, parentNode.Url);
                      if (panelitem.Text != rootitem.Text)
                      {
                          rootitem.Items.Add(panelitem);
                      }
                  }
              }
          }
      }


    Best wishes,
    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. Satya Vepa
    Satya Vepa avatar
    31 posts
    Registered:
    03 Dec 2009
    25 Jan 2010
    Link to this post
    Thanks Ivan for the code. But the code is displaying only SubSubItem1 as the menu. I need to display its parents menu.

    Thank you
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    25 Jan 2010
    Link to this post
    Hi Satya Vepa,

    You have to get Item1 which is Parent.Parent of the current item and get the Child items.

    Greetings,
    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.
  5. Satya Vepa
    Satya Vepa avatar
    31 posts
    Registered:
    03 Dec 2009
    25 Jan 2010
    Link to this post
    I tried
    foreach (CmsSiteMapNode parentNode.ParentNode in parent.ChildNodes)

    but no effect in the behaviour. any Ideas?

    Thanks
    Satya
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    25 Jan 2010
    Link to this post
    Hi Satya Vepa,

    Modify the code as shown below

    CmsSiteMapNode parent = item1.ParentNode.ParentNode as CmsSiteMapNode;
                   foreach (CmsSiteMapNode parentNode in parent.ChildNodes)
                   {
     
                       RadPanelItem rootitem = RadPanelbar1.FindItemByText(item1.Title);
                       if (rootitem != null)
                       {
                           RadPanelItem panelitem = new RadPanelItem(parentNode.Title, parentNode.Url);
                           if (panelitem.Text != rootitem.Text)
                           {
                               rootitem.Items.Add(panelitem);
                           }
                       }
                   }

    The code will generate the structure shown on the attached screenshot. If you have more levels deeper just recursively call the parent or use while loop.

    Best wishes,
    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.
  7. Satya Vepa
    Satya Vepa avatar
    31 posts
    Registered:
    03 Dec 2009
    25 Jan 2010
    Link to this post
    Ivan,
    I forgot to mention earlier. I tried
    CmsSiteMapNode parent = item1.ParentNode.ParentNode as CmsSiteMapNode;
    Even that did not help.

    Departments
      Department1
        Section1
        Section2
        Section3
      Department2
      Department3

    My Panelbar shows like following when you click on Department1
      Department1
        Section1
        Section2
        Section3
    When Clicked on Section1 it shows
    Section1

    What I need is When clicked on Section1 as section1 has no sub items to show, it should show Department1 items


    Thanks
    Satya

     


  8. Satya Vepa
    Satya Vepa avatar
    31 posts
    Registered:
    03 Dec 2009
    29 Jan 2010
    Link to this post

    Ivan,

     

    when I moved the code from Prerender to Pageload, the menu items of the parent are show along with the current Item.li ke the following

    SubSubItem1
    SubSubItem2
    SubSubItem3

    But the only problem is it shows SubSubItem1 with  ^ sybmol as root item.
    How Can I get the SubItem1 as Root element.

    Thanks
    Satya

     

     

  9. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    29 Jan 2010
    Link to this post
    Hi Satya Vepa,

    The is shown with ^ because it has child items or the EnableEmbeddedScripts property has been set to false. If this property is set to false and you are not loading the core script files from somewhere you will not be able to get the panel bar to function properly.

    You can check the item text or some other property and if it matches your item you can clear the child items of this item:
    foreach (RadPanelItem item in RadPanelbar1.Items)
    {
        if (item.Text == "ItemText")
        {
            if (item.Items.Count > 0)
            {
                item.Items.Clear();
            }
        }
    }


    Sincerely yours,
    Radoslav Georgiev
    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.
  10. Satya Vepa
    Satya Vepa avatar
    31 posts
    Registered:
    03 Dec 2009
    29 Jan 2010
    Link to this post

    I did set the EnableEmbeddedScripts = True and I am using WebBlue as skin. Is there any way I can add the parent Sitenode of the current node in to the panelbar Items.

    Thanks
    Satya
  11. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    01 Feb 2010
    Link to this post
    If I want to put a panelBar control onto a template and use this template for 4 levels of pages - Using the example below - how do I go about  showing only Department1, Department2, Department3 in the panelBarNav no matter what sub-page under departments you are on? -- I have set Display in naviation to none for all the section and subSection pages so they never show up. 

    And how to set the focus on Department 1 if you are on the Section1 page or SubSection1 page?

    Is that do-able with one control on one template?

    Departments
          Department1
            Section1
                  SubSection1
                  SubSection2
              Section2
              Section3
          Department2
              Section1
              Section2

          Department3
    Categories
    Wisgets
  12. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    02 Feb 2010
    Link to this post
    Hello Laura,

    You can add this to the ~/Sitefinity/UserControls/Navigation35/SitePanelbar.ascx.cs:

    [Browsable(true)]
    [Category("Navigation")]
    [WebEditor("Telerik.Cms.Web.UI.UrlEditorWrapper, Telerik.Cms")]
    public string StartingNodeUrl
    {
        get
        {
            return this.SiteMapDataSource1.StartingNodeUrl;
        }
        set
        {
            this.SiteMapDataSource1.StartingNodeUrl = value;
        }
    }

    This will let you select a node from the site map from which you want the panel bar to display items. Then on render you can get the current item and then get the parent until you reach the item you need to set its Selected property to true:

    CmsSiteMapNode currentNode = (CmsSiteMapNode)SiteMap.CurrentNode;
    RadPanelItem currentItem = this.PanelBar.FindItemByText(currentNode.CmsPage.MenuName);
    if (currentItem != null)
    {
       //get item parent using currentItem.Parent util you get the desired one and set its selected property to true.
    }

    Regards,
    Radoslav Georgiev
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
  13. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    02 Feb 2010
    Link to this post
    Thank you Radoslav,

    I am really close to the solution but don't have it quite just yet.
    Here are two jpg's (image1 and image2) of what I am trying to acheive.
    When on a third level page I need its parent (2nd level) to be selected and also need the very top level parent "selected".
    Also, if on the fourth level page, I need the 2nd level  and top level seleced.

    Is this still possible?

    Thank you!
    Laura

  14. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    02 Feb 2010
    Link to this post
    Maybe RadPanelBar (what I am currently using) is not the way to go on the left side nav since I do not want to expand any nodes ever. ???
  15. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    02 Feb 2010
    Link to this post
    Hi Laura,

    The RadPanelBar has only one selected item. You need to use css to make more than one item look selected.

    Below is the code the sets the Parent of the second level item as selected and sets the root item of the selected item as selected

    if (e.Item.Level == 2 && e.Item.Selected)
    {
                   RadPanelItem parent = (RadPanelItem)e.Item.Parent;
                   parent.CssClass = "yourSelectedCss";
     
                   CmsSiteMapNode p = SiteMap.CurrentNode as CmsSiteMapNode;
                   while (p != null && p.ParentNode != null)
                   {
                       if (p.ParentNode != SiteMap.RootNode)
                           p = (CmsSiteMapNode)p.ParentNode;
                       else
                           break;
                   }
                   RadPanelItem panleItem = this.RadPanelbar1.FindItemByUrl(this.ResolveUrl(p.Url).ToString());
                   if (panleItem != null)
                   {
     
                       panleItem.CssClass = "yourSelectedCss";
                   }
     }


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
  16. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    03 Feb 2010
    Link to this post
    Thanks Ivan.

    I got the main parent in the panel bar to be selcted!  But now I am having trouble getting the root node in the SiteMenuNav to be selected. (see image3.jpg)
    by the way - here is the code i used for getting the panel bar item selected. I allowed for three levels down.
    protected override void OnPreRender(EventArgs e)
     {
         base.OnPreRender(e);
                   
         foreach (RadPanelItem item in RadPanelbar1.GetAllItems())
         {
             item.Text = Convert.ToString(item.Level);
             if (item.Level == 1 && item.Selected)
             {
                 RadPanelItem parent = (RadPanelItem)item.Parent;
                 parent.CssClass = "rpSelected";
             }
             if (item.Level == 2 && item.Selected)
             {
                 RadPanelItem parent = (RadPanelItem)item.Parent.Parent;
                 parent.CssClass = "rpSelected";
             }
             if (item.Level == 3 && item.Selected)
             {
                 RadPanelItem parent = (RadPanelItem)item.Parent.Parent.Parent;
                 parent.CssClass = "rpSelected";
             }
         }
      }
  17. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    03 Feb 2010
    Link to this post
    Hi Laura,

    The header menu is a different control. You can get the currently selected item and then check its parent. Then highlight it. The code sample from my previous post does this no matter of the selected item level.

    CmsSiteMapNode p = SiteMap.CurrentNode as CmsSiteMapNode;
           while (p != null && p.ParentNode != null)
           {
               if (p.ParentNode != SiteMap.RootNode)
                   p = (CmsSiteMapNode)p.ParentNode;
               else
                   break;
           }
           RadMenuItem menuItem = this.RadMenu1.FindItemByUrl(this.ResolveUrl(p.Url).ToString());
           if (menuItem != null)
           {
     
               menuItem.SelectedCssClass = "somecss";
           }


    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
Register for webinar
17 posts, 0 answered