Simple ul>li>a list of pages

Posted by Community Admin on 04-Aug-2018 19:05

Simple ul>li>a list of pages

All Replies

Posted by Community Admin on 01-Sep-2011 00:00

I need to make/find a control that outputs the following for a menu for a given page. It should display all pages below a selected page. Basically like the treeview menu, only much simpler.

<ul class="simplemenu">
<li><a href="???">Page Title</a></li>
<li><a href="???">Page Title 2</a></li>
<li><a href="???">Page Title 3</a></li>
</ul>

How would you go about it? I'm assuming I need a user control with a repeater like this:

<asp:Repeater ID="Repeater1" runat="server">
    <HeaderTemplate>
        <ul class="simplemenu">
    </HeaderTemplate>
    <ItemTemplate>
        <li>
                <!-- Not quite sure what to put here to get the correct a tag.
                        probably an asp:hyperlink with unknown DataBinder code -->
        </li>
    </ItemTemplate>
    <FooterTemplate>
        </ul>
    </FooterTemplate>
</asp:Repeater>

And the code behind:

protected void Page_Load(object sender, EventArgs e)
        
            var PageList = App.WorkWith()
                .Pages()
                .LocatedIn(PageLocation.Frontend)
                .ThatArePublished()
                .Where(p => p.Parent.Id == ???)
                .Get()
                .ToList();
             
            Repeater1.DataSource = PageList;
            Repeater1.DataBind();
 
        

I'm not sure what to put in the where clause to get what I'm looking for yet. And i'm not sure if I'm outputting the right kind of data for the repeater.

Any suggestions? I feel like I'm close.

I would be happy to share this code when it is up and running.

Posted by Community Admin on 01-Sep-2011 00:00

Looks like my question is very similar to the one posted here:

Custom menu in 4.1
http://www.sitefinity.com/devnet/forums/sitefinity-4-x/developing-with-sitefinity/custom-menu-in-4-1.aspx

Posted by Community Admin on 01-Sep-2011 00:00

Also related to this question in the forum:
http://www.sitefinity.com/devnet/forums/sitefinity-4-x/developing-with-sitefinity/creating-a-simple-menu.aspx

Nevertheless, there still hasn't been a straight and complete answer. I'll keep looking and try to get a sample posted here when I solve this mystery.

Posted by Community Admin on 01-Sep-2011 00:00

The Sitefinity Marketplace has a free control that provides this capability called "CleanNav Control"

Find it here:
http://www.sitefinity.com/marketplace/modules/cleannav-control.aspx

Really useful. This kind of simple navigation is greatly needed in Sitefinity.

Posted by Community Admin on 06-Sep-2011 00:00

Hello Dan Sorensen,

Is the CleanNav control useful for you - was it what you were looking for?

All the best,
Lubomir Velkov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Posted by Community Admin on 06-Sep-2011 00:00

I'm sure you're looking to close this thread. ;-)

Short answer: yes, it is filling our present need.

Preferred answer: We'd love to see some sample source code in a blog or documentation on how to build a simple menu so that we can learn to modify it to better suit our needs. Something that doesn't rely on radmenu.

Posted by Community Admin on 08-Sep-2011 00:00

I can use the following code in a user control code behind and assign the markup string to a literal and get the desired result. This will collect all the siblings of this current page and show them in a unordered list that can be easily stylized to look like a menu.

// Get the current page.
PageSiteNode currentNode = SiteMapBase.GetCurrentProvider().CurrentNode as PageSiteNode;
 
// Find the siblings to this page.
var siblings = currentNode.ParentNode.ChildNodes;
 
string markup = "<ul>";
foreach (PageSiteNode s in siblings)
    markup += "<li><a href=\"" + Page.ResolveUrl(s.Url) + "\">" + s.Title + "</a></li>";
markup += "</ul>";

Posted by Community Admin on 08-Sep-2011 00:00

Is it possible to do the same as I listed above with the App.Workwith().Pages() syntax? Is it possible to find the siblings of the current page and iterate over the list and find the page title and url of each item?

I'm having trouble with it, but I think it is because the following code returns a PageNode and not a PageSiteNode.

// determine the current page id
Guid parentId = currentNode.PageId;
 
// get all published siblings of the current page
var siblings = App.WorkWith()
                   .Pages()
                   .LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
                   .ThatArePublished()
                   .ThatBelongTo(parentId)
                   .Get().ToList();
 
// Now how do we get the page title and url?
string markup = "<ul>";
foreach (PageNode s in siblings)
    // how do I get to the url or title of each sibling?
    // I can figure out the html 
  string markup += ???
string markup += "</ul>";

Posted by Community Admin on 08-Sep-2011 00:00

This might help. I think below code is pretty easy to adept to your own needs.

01.private void BuildMenu()
02.        
03.            var actualCurrentNode = SiteMapBase.GetActualCurrentNode();
04.            var parentNode = (PageSiteNode)actualCurrentNode.ParentNode;
05. 
06.            var nodeToTraverse = parentNode.Title == "Pages" ? actualCurrentNode : parentNode;
07. 
08.            var sb = new StringBuilder();
09. 
10.            sb.AppendFormat("<ul class='0'>", CssClass);
11. 
12.            if (nodeToTraverse.ChildNodes.Count > 0)
13.            
14.                foreach (var page in GetChildNodes(nodeToTraverse))
15.                
16.                    var node = (PageSiteNode)page;
17. 
18.                    var cssClass = string.Empty;
19. 
20.                    if (node.ShowInNavigation)
21.                    
22.                        if (node.Id == SiteMapBase.GetActualCurrentNode().Id)
23.                            cssClass = "active";
24. 
25.                        sb.AppendFormat("<li><a href='1' class='2'>0</a></li>", node.Title, ResolveUrl(node.Url), cssClass);
26.                    
27.                
28.            
29. 
30.            sb.Append("</ul>");
31. 
32.            ltlOutput.Text = sb.ToString();
33.        
34. 
35.private static PageSiteNodeCollection GetChildNodes(SiteMapNode siteMapNode)
36.        
37.            var pageSiteNodeCollection = new PageSiteNodeCollection();
38. 
39.            foreach (var page in siteMapNode.ChildNodes)
40.            
41.                var node = (PageSiteNode)page;
42. 
43.                if (node.ShowInNavigation)
44.                
45.                    pageSiteNodeCollection.Add(node);
46.                
47.            
48. 
49.            return pageSiteNodeCollection;
50.        

This thread is closed