Copied to clipboard

Flag this post as spam?

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


  • Chris Clancy 64 posts 133 karma points
    Dec 13, 2016 @ 10:28
    Chris Clancy
    0

    Query builder / general content query questions

    Hi,

    I have a looked at the Querying documentation and used the query builder a few times but I don't like using content nodes in queries as it is possible that they will change and also they won't be the same across different environments when using different databases.

    What I'm trying to do should be very simple but I can't get it to work.

    I have a multi site setup and am trying to create a footer which users can build/edit. I have a Folder doc type containing a bunch of 'link groups' which are essentially a doc type with a title and multi picker.

    If I use the standard query builder it all works but I want to specify a folder name or more reliable way instead of a node id for searching.

    My working query goes like this:

    var selection = Umbraco.Content(2225).Children().Where("Visible")
    

    What I want is 'all of the LinkGroupList' items within a folder named 'SiteFooterLinks'. I've tried so many different ways to get this with no joy. Also, I'd like to know what is the most efficient way of doing this!

    Thanks

    Chris

  • Søren Kottal 712 posts 4570 karma points MVP 6x c-trib
    Dec 21, 2016 @ 21:16
    Søren Kottal
    0

    Hi Chris

    Try using Umbraco.TypedContentAtXPath().

    The following statement is extremely fast, because it is so specific in where to find the content. This requires that your SiteFooterLinks nodes are located in the root of your content tree. But you can type any path you want.

    var selection = Umbraco.TypedContentAtXPath("/root/SiteFooterLinks/LinkGroupList");
    

    You could also do

    var selection = Umbraco.TypedContentAtXPath("//SiteFooterLinks/LinkGroupList");
    

    This is not as performant, because it would search the whole tree for SiteFooterLinks nodes, and then select their LinkGroupList children.

Please Sign in or register to post replies

Write your reply to:

Draft