Custom Sitemap

Posted by Community Admin on 04-Aug-2018 17:58

Custom Sitemap

All Replies

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

I am developing a custom sitemap which integrates products from my custom product module in to the site map. I am seeing some strange behavior in the Custom sitemap where products only appear some of the time. I think it may be something to do with caching of the sitemap nodes but I am just not sure.

I developed the custom sitemap by inheriting from PageSiteNode as follows.

using System;
using Dannon.Sitefinity.ProductModule.Model;
using Telerik.Sitefinity.Data;
using Telerik.Sitefinity.Pages.Model;
using Telerik.Sitefinity.Web;
 
namespace Dannon.Sitefinity.Web.UI
    public class ProductSiteNode : PageSiteNode, ISitefinitySiteMapNode
    
        public string ProductProviderName get; private set;
 
        public ProductItem Product get; private set;
 
        public override string Url
        
            get
            
                return "~/products/details/" + this.Product.UrlName;
            
            set
            
                throw new NotSupportedException();
            
        
 
        public override string Title
        
            get
            
                return Product.NavigationTitle;
            
            set
            
                throw new NotSupportedException();
            
        
 
        public ProductSiteNode(SiteMapBase provider, PageNode pageNode, string pageProviderName, ProductItem product, string productProviderName)
            : base(provider, pageNode, pageProviderName)
        
            this.CacheDependency = new CompoundCacheDependency();
            this.CacheDependency.CacheDependencies.Add(new DataItemCacheDependency(product.GetType(), product.Id));
 
            if (provider == null)
            
                throw new ArgumentNullException("provider");
            
            this.ProductProviderName = productProviderName;
            Product = product;
        
    

I then overrode GetChildNodes in my custom sitemap provider inherited from SitefinitySiteMap.
public override SiteMapNodeCollection GetChildNodes(SiteMapNode parent, bool ifAccessible)
    var taxMan = GetTaxonomyManager();
    var departments = taxMan.GetTaxonomy(ProductsModule.DepartmentTaxonomyId).Taxa;
    SiteMapNodeCollection childNodes = base.GetChildNodes(parent, ifAccessible);
  
    var department = departments.FirstOrDefault(d => parent.Url.EndsWith(d.UrlName));
  
    if (department != null)
    
        foreach (var product in GetProductsByTaxon(department.Title, "Departments"))
        
            var parentPage = parent as PageSiteNode;
            var parentPageNode = GetPageManager().GetPageNode(parentPage.Id);
            childNodes.Add(GetSiteMapNodeForProduct(parentPageNode, product));
        
    
    return childNodes;

Is this the correct way to implement a custom SiteMapProvider in sitefinity? Are there any examples of a custom sitemap provider in Sitefinity 4.2 SP1.

Thanks,
Jason Chester

Posted by Community Admin on 07-Oct-2011 00:00

Hi Jason Chester,

We apologize for the late answer. We don't have a sample for custom site map. But what you did seams OK. Could you tell us when you stop to see the products in the navigation? We created a test project based on your code and it looks it works.

Best wishes,
Ivan Pelovski
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 07-Oct-2011 00:00

Jason, I am working on a Sitemap implementation myself, and will blog my solution soon...

however I'm curious about your approach. Why do you use the sitemap and sitenodes? It might be easier to simply use the API to retrieve items (pages, news, products, etc) then build the xml manually, avoiding the sitemapnodes altogether. this is the approach I am taking.

I don't know if this is related to your problem, but I think retrieving products through the API might automate internally the caching stuff so you can just grab the data you need (correct me if I'm wrong sf guys!)

hope this is helpful, I'll try to publish my work asap!

Posted by Community Admin on 07-Oct-2011 00:00

I decided to base my code on the existing sitemap implementation so I could take advantage of all the caching and performance built in to it. SitefinitySiteMap is a pretty complicated class and I wanted to maintain all it's functionality without duplicating the code.

Inheriting from SitefinitySiteMap also means that I should be able to take advantage of any of the changes to the base implementation on version upgrades without having to change my code.

I think the issues I have seen were more about my navigation control, based on CleanNav, than my sitemap provider.  After some debugging of the CleanNav code it is working well so I am happy with my approach.

Jason

This thread is closed