Sitemapbase not working as expected

Posted by Community Admin on 05-Aug-2018 11:33

Sitemapbase not working as expected

All Replies

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

Hi,

I'm trying to use the sitemapbase to get all of the child nodes of the root node. I would have presumed the root node was the home page. I would have also expected it to only return pages that have been published. The following simple line of code is returning all top level pages, including those that arent published and those that I have explicitly asked not to be shown in the navigation.

SiteMapNodeCollection oNodes = SiteMapBase.GetCurrentProvider().GetChildNodes(SiteMapBase.GetCurrentProvider().RootNode);

Am i doing something wrong?

Thanks
higgsy

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

Hello higgsy,

You can use the fluent API to get pages with a given status.

var pages = App.WorkWith().Pages().Where(page => page.ApprovalWorkflowState == "Draft").Get();

You can use

  • Published
  • Draft
  • AwaitingApproval
  • Scheduled ( for content items)
The methods you use does not have filters of the status.
Regards,
Ivan Dimitrov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.

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

Ivan,

Perfect - a quick follow up question. In 3.7 the root node was always the home page, so i could essentially get all child nodes of the home page. V4 seems to be different, therefore:

- Which node is regarded as the root node
- How would I extend the expression to get only top-level pages?

Quick support - thanks alot.

Thanks
higgsy

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

Ivan,

Think ive got it, unless you see a problem with it.

var pages = App.WorkWith().Pages().Where(page => page.ApprovalWorkflowState == "Published" && page.ShowInNavigation == true && page.Parent == page.RootNode).Get();

Thanks
higgsy

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

Hello higgsy,

If you want to get all pages on the front end you can use App.WorkWith().Pages().LocatedIn(PageLocation.Frontend), because App.WorkWith().Pages() allows you to get backend pages as well.

Best wishes,
Ivan Dimitrov
the Telerik team


Check out Telerik Trainer, the state of the art learning tool for Telerik products.

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

Hi Ivan,

Thanks for your response.

Ok, are you therefore saying that we should no longer be using the sitemap for building navigation controls, as we did in v3.7? 3.7 only added a page to the sitemap once it was published.

Finally, if we are not using the sitemap (which obviously has a nice hierarchical xml structure), how would I do the following:

If I am on the page mydomain.com/services/digital-print

I need to get the highest node, which is not the root node. In the above example it would obviously be /services/

Previously I have always used the following code (which just doesnt seem to work in V4):

private SiteMapNode GetParentNode(SiteMapNode CurrentNode)
 
    SiteMapNode RootSiteMapNode = SiteMap.RootNode;
    SiteMapNode CurrentSiteMapNode = CurrentNode;
 
    //loop through all nodes until we reach the top level prior to the homepage node
    while (CurrentSiteMapNode.ParentNode != null && (SiteMapNode)CurrentSiteMapNode.ParentNode != RootSiteMapNode)
 
        bool test = ((SiteMapNode)CurrentSiteMapNode.ParentNode == RootSiteMapNode);
 
        CurrentSiteMapNode = CurrentSiteMapNode.ParentNode;
 
    
 
    return CurrentSiteMapNode;
 

Thanks again
higgsy

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

Hello higgsy,

You can get the frontend root node

var root = Config.Get<PagesConfig>().FrontendRootNode;
var pgs = App.WorkWith().Pages().Where(pk => pk.Name == root).Get().SingleOrDefault() as PageNode;

Then  you can get the actual current node

var psn  = SiteMapBase.GetActualCurrentNode();
var pgn1 = manager.GetPageNode(psn.Id);

and look for its parent until you reach the root page node.

Kind regards,
Ivan Dimitrov
the Telerik team


Check out Telerik Trainer, the state of the art learning tool for Telerik products.

This thread is closed