Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example dynamic Umbraco sitemap.xml template
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = null;
umbraco.library.ChangeContentType("text/xml");
}
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
@foreach (var root in Umbraco.TypedContentAtRoot())
{
<url>
<loc>@root.HasValue("canonicalUrl", root.GetPropertyValue<string>("canonicalUrl"), root.UrlAbsolute())</loc>
<lastmod>@root.UpdateDate.ToString("yyyy-MM-ddTHH:mm:00")+00:00</lastmod>
@if(root.HasValue("updateFrequency"))
{
<changefreq>@root.GetPropertyValue("updateFrequency")</changefreq>
}
</url>
foreach (var content in root.Descendants().Where(c => c.GetPropertyValue<string>("noIndex", "True") == "False"))
{
<url>
<loc>@content.HasValue("canonicalUrl", content.GetPropertyValue<string>("canonicalUrl"), content.UrlAbsolute())</loc>
<lastmod>@content.UpdateDate.ToString("yyyy-MM-ddTHH:mm:00")+00:00</lastmod>
@if (content.HasValue("updateFrequency"))
{
<changefreq>@content.GetPropertyValue("updateFrequency")</changefreq>
}
</url>
}
}
</urlset>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment