Skip to content

Specifying your own logic

Radek Kozłowski edited this page Oct 13, 2016 · 4 revisions

You can specify your own logic, that can add your custom items to the sitemap, e.g. some static html pages or other links that exist outside Sitecore.

You should create class that implements IItemsProcessor interface

public interface IItemsProcessor
{
    List<UrlElement> ProcessItems(SitemapSiteConfiguration sitemapSiteConfiguration);
}

For example:

/// <summary>
/// Sample items processor 
/// Adds some custom elements to sitemap
/// </summary>
public class SampleItemsProcessor : IItemsProcessor
{
    public List<UrlElement> ProcessItems(SitemapSiteConfiguration sitemapSiteConfiguration)
    {
        var items = new List<UrlElement>();

        if (sitemapSiteConfiguration.LanguageName == "en")
        {
            items.Add(new UrlElement
            {
                Location = "http://mysite.com/some-custom-static-page.html",
                Priority = "0.7",
                LastModification = new DateTime(2016, 03, 01),
                ChangeFrequency = "yearly"
            });
        }
            
        return items;
    }
}

A last you should attach your class to the site configuration item, in format MyType, MyAssembly:

Configurations

Solution has example project Sitecore.SharedSource.DynamicSitemap.ItemsProcessor

Clone this wiki locally