I'm a bit confused, using the API there are three ways (I have found anyway) to look for content in a SufraceController:
Using the UmbracoHelper
Using the ContentService
Using uQuery
If I want to find a specific node I never know which one to use and why. The documentation doesn't really puts one over the other, except to say that uQuery is being replaced by the UmbracoHelper, but they seem to work completely different.
For instance, if I want to find a particular node by it's document type, in uQuery I can say:
umbraco.uQuery.GetNodesByType("SomeType").First()
I can't seem to find a similar way to do this using the UmbracoHelper or the ContentService. In addition, the UmbracoHelper returns either a dynamic or an IPublishedContent interface implementation, which seems to lack any search function (like the Decendents() method).
Maybe I'm going about this all wrong, but every time I want to look for something using the API, usually in a SurfaceController, I'm completely lost as to what approach to take...
What is the difference between the three APIs and what do you do to find Content?
Ah I see, I fear my knowledge of XPath is pretty limited and the page you refer to also has very little information as to how to query using XPath.
Do you happen to know if there is any documentation 'out there' that describes how this works and what else I can do with the TypedContentAtXPath method?
Also, I didn't realise that the methods like Decendents() are extension methods to IPublishedContent. Having these methods available answers nearly all my questions :)
The reason to use published content (only) is that you don't go to the database.
However, you can do that by using ApplicationContext.Services.ContentService.
Not that many querying options with content, though. There's no LINQ to SQL going on. (AFAIK)
Finding content via Api
I'm a bit confused, using the API there are three ways (I have found anyway) to look for content in a SufraceController:
If I want to find a specific node I never know which one to use and why. The documentation doesn't really puts one over the other, except to say that uQuery is being replaced by the UmbracoHelper, but they seem to work completely different.
For instance, if I want to find a particular node by it's document type, in uQuery I can say:
I can't seem to find a similar way to do this using the UmbracoHelper or the ContentService. In addition, the UmbracoHelper returns either a dynamic or an IPublishedContent interface implementation, which seems to lack any search function (like the Decendents() method).
Maybe I'm going about this all wrong, but every time I want to look for something using the API, usually in a SurfaceController, I'm completely lost as to what approach to take...
What is the difference between the three APIs and what do you do to find Content?
For published content, you should use UmbracoHelper.
To find nodes by type, you can use Umbraco.TypedContentAtXPath("//SomeType").
IPublishedContent has a lot of extensions, like Descendants().
See https://github.com/umbraco/Umbraco4Docs/blob/master/Documentation/Reference/Querying/UmbracoHelper/index.md
Ah I see, I fear my knowledge of XPath is pretty limited and the page you refer to also has very little information as to how to query using XPath.
Do you happen to know if there is any documentation 'out there' that describes how this works and what else I can do with the TypedContentAtXPath method?
Also, I didn't realise that the methods like Decendents() are extension methods to IPublishedContent. Having these methods available answers nearly all my questions :)
TypedContentAtXPath searches the xml file umbraco.config under App_Data. (Actually an in-memory version, I believe)
Maybe this will help you out:
http://www.w3schools.com/XPath/
The reason to use published content (only) is that you don't go to the database.
However, you can do that by using ApplicationContext.Services.ContentService.
Not that many querying options with content, though. There's no LINQ to SQL going on. (AFAIK)
is working on a reply...