Custom Navigation User Control

Posted by Community Admin on 04-Aug-2018 13:42

Custom Navigation User Control

All Replies

Posted by Community Admin on 05-Mar-2013 00:00

All,

I`m new to SiteFinity and I<m trying to build a custom user control for my top navigation to reproduce the top nav from this site: http://wet-boew.github.com/wet-boew/demos/index-eng.html

I will call the user control from my master page.  Unsure what SiteMapProvider to use or if I should use that.

 

Thank you for the help and if you have example code behind to get me started would be appreciated.

Mathieu

Posted by Community Admin on 05-Mar-2013 00:00

Hi All,

 

Well, I think I`m on to something but here is some code I tried and it didn`t crash.

<code>protected override void Render(HtmlTextWriter writer)
       

SiteMapProvider oMap = SiteMapBase.GetCurrentProvider();
            SiteMapNode oMapNode;
            htmlOutput="<ul class='mb-menu'>";
            bool isfirst = true;
            oMapNode = oMap.CurrentNode;
            // foreach (SiteMapNode node in oMap.CurrentNode.ChildNodes)
            foreach (SiteMapNode node in oMapNode.ChildNodes)
           
                // add the children of the root site
                //htmlOutput += renderTopLevelLink(node, isfirst, currUrl);
                htmlOutput += "<li><div><a href='"+node.Url.ToString()+"'>"+node.Title.ToString()+"</a></div></li>";
                isfirst = false;
           
           htmlOutput += "</ul>";

</code>

This code returns me all pages regardless if it is published or not and also returns the starting node which I don't want.

 

Posted by Community Admin on 08-Mar-2013 00:00

Hello,

To build custom navigation control its best to use the datasource that sitefintiy uses SitefinitySitemapDataSource which is optimized for handling sitefinity pages and multilingual scenarious.

<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.NavigationControls" TagPrefix="sfMap" %>
    
<sfMap:SitefinitySiteMapDataSource ID="SM" runat="server" ShowStartingNode="false" />
 To hide the starting root node in the data source specify ShowStartingNode = false as highlighted.

All the best,
Stanislav Velikov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 08-Mar-2013 00:00

I've read up on that and understand that but in code behind I'm uncertain on how to call the the datasource and attach that to a sitemapnode to use is and go through it.

Posted by Community Admin on 13-Mar-2013 00:00

Hello Mathieu,

SitefinitySiteMapDataSource is a declarative control, i.e. it would provide the datasource automatically to the control which will use it. You can then subscribe to ItemDataBound event of that control and implement some custom logic for modifying the item when it's bound to the control, since this event will fire for every item that gets bound.


Greetings,
Boyan Barnev
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed