Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Jun 24, 2011 @ 14:47
    Anthony Dang
    0

    Razor version issue

    When umbracoNaviHide is set to true on a node (say a container) but you want the sitemap to display it's children, then the script will not get the children.

    This may not apply to everyone but this is what I did to the script:

     

    @ListChildNodes(Model.AncestorOrSelf(1))

    @helper ListChildNodes(dynamic startNode)
    {
    Response.ContentType = "text/xml";
    const int maxLevelForSiteMap = 100;

    foreach (var node in startNode.Children)
    {
    if (node.template > 0)
    {
    if (node.umbracoNaviHide == false && node.HasAccess && !node.IsProtected)
    {
  • Bojan 16 posts 131 karma points
    Dec 29, 2016 @ 16:09
    Bojan
    0

    Hi Anthony,

    I needed this solution also so I've changed the code to support parent nodes (containers or classic pages) to work with umbracoNaviHide.

    @using Umbraco.Core.Models
    @using Umbraco.Web
    
    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{
        var startNode = Model.Content.AncestorOrSelf(1);
    }
    
    @CreateXML(startNode) 
    
    @ListChildNodes(startNode)
    
    @helper ListChildNodes(IPublishedContent startNode)
    {
        Response.ContentType = "text/xml";
    
        const int maxLevelForSiteMap = 100;
    
        foreach (var node in startNode.Children)
        {
            if (node.TemplateId > 0)
            {
                @CreateXML(node)
            }
    
            if (node.Level <= maxLevelForSiteMap && node.Children.Any())
            {
                @ListChildNodes(node)
            }
        }
    }
    
    @helper CreateXML(IPublishedContent node) 
    {
        if (node.IsVisible() && Umbraco.MemberHasAccess(node.Path) && !Umbraco.IsProtected(node.Path))
        {
            <url>
                <loc>@node.UrlAbsolute()</loc>
                <lastmod>@($"{node.UpdateDate:s}+00:00")</lastmod>
    
                @{
                    var frequency = node.GetPropertyValue<string>("SearchEngineSitemapChangeFreq");
                    var priority = node.GetPropertyValue<string>("SearchEngineSitemapPriority");
                }
    
                @if (!string.IsNullOrEmpty(frequency))
                {
                    <changefreq>@frequency</changefreq>
                }
    
                @if (!string.IsNullOrEmpty(priority))
                {
                    <priority>@priority</priority>
                }
            </url>
        }
    }
    

    Cheers,

    Bojan

Please Sign in or register to post replies

Write your reply to:

Draft