Skip to content

Instantly share code, notes, and snippets.

@glcheetham
Last active October 12, 2016 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glcheetham/5612fd1d28fd36e62638cd85105cbe0e to your computer and use it in GitHub Desktop.
Save glcheetham/5612fd1d28fd36e62638cd85105cbe0e to your computer and use it in GitHub Desktop.
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