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!
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.
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:
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
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.
You could also do
This is not as performant, because it would search the whole tree for SiteFooterLinks nodes, and then select their LinkGroupList children.
is working on a reply...