Copied to clipboard

Flag this post as spam?

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


  • Brian McNally 16 posts 104 karma points
    Sep 18, 2024 @ 18:03
    Brian McNally
    0

    Filtering based on contentment Data List

    I apologize in advance if I'm not summarizing the ask correctly but I'm not too familiar with this so bear with me.

    We are on a Umbraco Cloud v8 site and use a contentment data list to specify our Robots SEO options for any given page on the website to be used as the meta robots content. It's a user defined checkbox list to allow our content editors to select from No Index, No Follow, etc. If no value is selected than index it the default I believe.

    For the various sitemap XML cshtml template files I'm trying to REMOVE any pages that are marked as no index.editor settings

    Property Settings

    So for the template file for the XML sitemap page I have the following query to get the pages I need (in this case it's an XML template just for our press releases)

    var newsselection = Umbraco.Content(Guid.Parse("xxxx-xxxxx-xxxxx(actual guid here)"))
        .DescendantsOfType("PressRelease")
    .Where(x => x.IsVisible());
    

    I guess my question is, can I add another where statement here which would not pull in pages that are listed as no index? I have tried a couple different ways but I'm not sure of the syntax to use here. We used to have a boolean option for hide from XML sitemap and that was easy just using:

     .Where(x => x.Value<bool>("HideFromXmlSitemap") == false);
    

    The structure has been updated to use the contentment data list but I'm just not familiar with how to work with it. I'm hoping it's a simple syntax I can use, any ideas? Thank you in advance!!!

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Sep 19, 2024 @ 09:31
    Lee Kelleher
    100

    Hi Brian,

    For the Data List configuration you have (user-defined data-source with a checkbox-list), the C# value type would be a List<string>, so you could try something like this...

    .Where(x => x.Value<List<string>>("RobotOptions").Contains("noIndex") == false);
    

    I hope this helps.

    Cheers,
    - Lee

  • Brian McNally 16 posts 104 karma points
    Sep 20, 2024 @ 20:45
    Brian McNally
    0

    Thanks Lee! That looks like it would make sense to me, but I get the old "Object reference not set to an instance of an object." when I try that. Not sure what's up enter image description here

  • Brian McNally 16 posts 104 karma points
    Sep 23, 2024 @ 20:49
    Brian McNally
    0

    Hi Lee, Just a quick update on my end. Our data set had some items that had null or empty values on that data set so that was causing the error. For now I've updated the query to account for that and it's working great. Thanks again Lee

    .Where(x =>
    {
        var robotsOptions = x.Value<List<string>>("RobotsOptions");
        return robotsOptions == null || !robotsOptions.Any() || !robotsOptions.Contains("noindex");
    });
    
  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Sep 24, 2024 @ 07:30
    Lee Kelleher
    0

    Super, glad that you got it working! 👍

Please Sign in or register to post replies

Write your reply to:

Draft