Sitemap: List all nodes from specific group page

Posted by Community Admin on 03-Aug-2018 16:32

Sitemap: List all nodes from specific group page

All Replies

Posted by Community Admin on 04-Jan-2011 00:00

Hey all,

I've been recently playing around and wrapping my head around Sitefinity 4. At the moment, I'm having an issue with using a collection type control, such as a repeater, to display information from a sitemap.

Here is what I'm attempting to do.

If I have a series of pages like the following:

1. Home
2. Members
     a. Sub Page 1
     b. Sub Page 2
     c. Sub Page 3
     d. Sub Page 4

If in the Members group page I want to display a list of all pages below this parent how do I go about it?

Note, for the Members group page and all sub pages I am using a master page, and using a site map data source and a repeater in that master page.

Here is some sample code of mine:

-- In the mark up of the master page:
I have a stiemap datasource and repeater
'<asp:Repeater ID="TopNavRepeater" OnItemDataBound="TopRepeater_ItemDataBound" runat="server">
     <ItemTemplate>
          <asp:HyperLink ID="TopNavRepeaterHyperLinkItem" CssClass="headerLink" runat="server" />
     </ItemTemplate>
</asp:Repeater>
<asp:SiteMapDataSource id="SiteMapDataSourceTop" StartingNodeUrl="~/Members/" runat="server" />'

-- then in the codebehind of the master page:
I set the data source on the repeater and bind it on Page_Load.

'protected void Page_Load(object sender, EventArgs e)

     TopNavRepeater.DataSource = SiteMapDataSourceTop;
     TopNavRepeater.DataBind();
'

I also have a delegate set up for the OnItemDataBound event.
'protected void TopNavRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)

     PageSiteNode pageSiteNode = (PageSiteNode)e.Item.DataItem;
     HyperLink hyperLink = (HyperLink)e.Item.FindControl("TopNavRepeaterHyperLinkItem");
     hyperLink.NavigateUrl = pageSiteNode.Url;
     hyperLink.Text = pageSiteNode.Title;
'

-- I have a item data bound delegate set:

I would have thought this is the basic approach to use, but when viewed in the browser I only see one node displayed. However, if I change the DataSource on the repeater in Page_Load to this:

'protected void Page_Load(object sender, EventArgs e)

     TopNavRepeater.DataSource = SiteMap.RootNode.GetAllNodes();
     TopNavRepeater.DataBind();
'

then, it shows all nodes. This is not what I really want.

Oh, and by the way, how do you paste in code snippets? The description at the top on insert new post isn't that helpful.

Posted by Community Admin on 04-Jan-2011 00:00

Hello Doug,

If in the Members group page I want to display a list of all pages below this parent how do I go about it?


You can use the fluent API to get the page node and then check for its child nodes

sample

var pg = App.WorkWith().Pages().Where(pk => pk.Name == "somename").Get().SingleOrDefault() as PageNode;
var pagenode = pg as PageSiteNode;
if (pagenode.IsGroupPage && pagenode.HasChildNodes)
 


Regards,
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

Posted by Community Admin on 04-Jan-2011 00:00

However, if I am on Sub Page 1, I'd still like to see a link to

Sub Page 1, Sub Page 2, Sub Page 3, Sub Page 4.

The same holds true if I am on Sub Page 3,

I want to see links to Sub Page 1, Sub Page 2, Sub Page 3, Sub Page 4.

Also, if I am on the Members group page, I want to see links to all the child pages.

Here's an example when using a sitemap in asp.net

<sitemapnode "/Members/Members.aspx" ......................>
     <sitemapnode "/Members/SubPage1.aspx" ..................... />
     <sitemapnode "/Members/SubPage2.aspx" ..................... />
     <sitemapnode "/Members/SubPage3.aspx" ..................... />
     <sitemapnode "/Members/SubPage4.aspx" ..................... />
</sitemapnode>

Now, the Members.aspx, and all sub pages use the same master page. In that master page, there is a sitemapdatasource with starting node url of "~/Members/".

Then with a repeater I can point the datasource to the sitemapdatasource and on item data bound, and the repeaters items count will be 5. And then for each item template, I can set the url and title to the hyperlink.

This is what I'm trying to do.

Posted by Community Admin on 04-Jan-2011 00:00

Your code example isn't working.

When I do:

var pg = App.WorkWith().Pages().Where(pk => pk.Name == "somePageName").Get().SingleOrDefault() as PageNode;

var pageNode = pg as PageSiteNode;

I get a red underline at 'pg as PageSiteNode' with Error: 'Cannot convert type 'Telerik.Sitefinity.Pages.Model.PageNode' to 'Telerik.Sitefinity.Web.PageSiteNode' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion.

Any thoughts?

Posted by Community Admin on 04-Jan-2011 00:00

Ok, I found the solution to my problem.

In master page:
<asp:Repeater ID="TopNavRepeater" OnItemDataBound="TopNavRepeater_ItemDataBound" runat="server">
     <ItemTemplate>
          <asp:HyperLink ID="TopNavRepeaterHyperLinkItem" CssClass="headerLinks" runat="server" />
     </ItemTemplate>
</asp:Repeater>

In master page codebehind:
protected void Page_Load(object sender, EventArgs e)

     TopNavRepeater.DataSource = SiteMapBase.GetCurrentProvider().FindSiteMapNode("Home").ChildNodes;
     TopNavRepeater.DataBind();


// ItemDataBound delegate
protected void TopNavRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)

     PageSiteNode pageSiteNode = (PageSiteNode)e.Item.DataItem;
     HyperLink hyperLink = (HyperLink)e.Item.FindControl("TopNavRepeaterHyperLinkItem");
     hyperLink.NavigateUrl = pageSiteNode.Url;
     hyperLink.Text = pageSiteNode.Title;

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

Hello All,

I got all sub nodes of "Home" by using  this SiteMapBase.GetCurrentProvider().FindSiteMapNode("Home").ChildNodes;
I like to order this nodes as per the CMS admin order . Now its showing by the created date. How can I change the order of this list

Thanks in advance
Roopesh

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

Hi Roopesh,

You need a list ordered by Descending based on the PageNode title. Below is a sample code

var pgs = App.WorkWith().Pages().LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend).Get().OrderByDescending(t => t.Title).Reverse();

Kind regards,
Ivan Dimitrov
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 09-Aug-2011 00:00

Hello

I have  created a menu item using Radmenu. When I click on one menu item I want to apply selected item css dynamically. How can I do it in the ItemDataBound(object sender, RadMenuEventArgs e) property

Thank you
Roopesh

Posted by Community Admin on 09-Aug-2011 00:00

Hello Roopesh,

e.Item.DataItem is the PageNode so you can make the menu item selected using item.Selected property


sample


RadMenuItem item = this.RadMenu1.FindItemByUrl(this.ResolveUrl(currentNode.Url));
            if (item != null)
                item.Selected = true;

Kind regards,
Ivan Dimitrov
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 09-Aug-2011 00:00

Hello
Thanks for the reply

Here how can I get the current node?

Thank You

Roopesh

Posted by Community Admin on 09-Aug-2011 00:00

Hello Roopesh,

Use SiteMapBase.GetActualCurrentNode(). The method has been suggested sever times in the forum and if you search for it you will find more samples.

Kind regards,
Ivan Dimitrov
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 09-Aug-2011 00:00

Hello

I am little confused about this usage . I will paste my code here
HTML
-----------------


<telerik:RadMenu ID="TopNavRepeater" runat="server" Width="100%" EnableEmbeddedSkins="false"
    Skin="small_menu_bar ">
</telerik:RadMenu>



CS
-----------------
 protected void Page_Load(object sender, EventArgs e)
   
        if (!IsPostBack)
       
            RadMenuItem item = this.TopNavRepeater.FindItemByUrl(SiteMapBase.GetActualCurrentNode().Url);
            if (item != null)
                item.Selected = true;
            TopNavRepeater.DataSource = SiteMapBase.GetCurrentProvider().FindSiteMapNode("CMA").ChildNodes;
            TopNavRepeater.DataBind();

            
       
   

But its not getting selected

Can you please check this

Thank you
Roopesh

This thread is closed