-
Notifications
You must be signed in to change notification settings - Fork 7
Specifying your own logic
Radek Kozłowski edited this page Oct 14, 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
{
/// <summary>
/// Method that will process your items
/// </summary>
/// <param name="sitemapSiteConfiguration">Sitemap site configuration to which items will be added</param>
/// <returns>List of your items</returns>
public List<UrlElement> ProcessItems(SitemapSiteConfiguration sitemapSiteConfiguration)
{
var items = new List<UrlElement>();
// - Let's check for specific language -
if (sitemapSiteConfiguration.LanguageName == "en")
{
// - Add your own elements packed into object of UrlElement class -
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 collected items -
return items;
}
}
A last you should attach your class to the site configuration item, in format MyType, MyAssembly
:
Solution has example project Sitecore.SharedSource.DynamicSitemap.ItemsProcessor