How to access root level nodes used for configuration
Umbraco version: 7.2.4
We've used root level nodes as placeholders for global settings as well as language-specific settings - but I cant see how to access these pages in a reasonable manner using the ... well... sparsely documented razor api.
Our content tree looks a bit like:
UK site (document type "Home") - subpage 1 - subpage 2 DK site (document type "Home") Global settings (document type "Global Settings") UK settings (document type "Site Settings") DK settings (document type "Site Settings")
When I render the master template, I'd like to access settings like
var globalSettings = CurrentPage.AncestorsOrSelf(0).Where(docmenttype="GlobalSettings")
and
var siteSettings = <some query that takes into account the selected language for the page we're on>
I've been able to get the global settings node like this
var gs = Umbraco.ContentSingleAtXPath("//GlobalSettings");
- but it looks like a hack, and I can't figure out how to expand it to get the language-specific settings node.
@foreach (var child in Umbraco.ContentAtRoot().Children) {
<a href="@child.Url">@child.Name</a>
}
- which on my machine gives this
Server Error in '/' Application.
'Umbraco.Web.Models.DynamicPublishedContentList' does not contain a definition for 'Children'
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Umbraco.Web.Models.DynamicPublishedContentList' does not contain a definition for 'Children'
Can anybody help finding the nodes - or point me to the documentation?
There's no children because ContentAtRoot() is returning a list of content (all of the content items in the root).
It's easier to spot these things is you use TypedContent, as you can see in the code completion in (for example) WebMatrix what you'll get back.
So this should work:
@foreach (var child in Umbraco.TypedContentAtRoot()) {
<a href="@child.Url">@child.Name</a>
}
How to access root level nodes used for configuration
Umbraco version: 7.2.4
We've used root level nodes as placeholders for global settings as well as language-specific settings - but I cant see how to access these pages in a reasonable manner using the ... well... sparsely documented razor api.
Our content tree looks a bit like:
UK site (document type "Home")
- subpage 1
- subpage 2
DK site (document type "Home")
Global settings (document type "Global Settings")
UK settings (document type "Site Settings")
DK settings (document type "Site Settings")
When I render the master template, I'd like to access settings like
var globalSettings = CurrentPage.AncestorsOrSelf(0).Where(docmenttype="GlobalSettings")
and
var siteSettings = <some query that takes into account the selected language for the page we're on>
I've been able to get the global settings node like this
var gs = Umbraco.ContentSingleAtXPath("//GlobalSettings");
- but it looks like a hack, and I can't figure out how to expand it to get the language-specific settings node.
When I look at the "documentation" I constantly hit issue after issue with samples that were for v6 or the like, and even https://our.umbraco.org/DOCUMENTATION/Reference/Querying/UmbracoHelper/ which should be for v7 seem to be misleading. One of the samples is
- which on my machine gives this
Server Error in '/' Application.
'Umbraco.Web.Models.DynamicPublishedContentList' does not contain a definition for 'Children'
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Umbraco.Web.Models.DynamicPublishedContentList' does not contain a definition for 'Children'
Can anybody help finding the nodes - or point me to the documentation?
Thanks in advance :)
/Jan
There's no children because ContentAtRoot() is returning a list of content (all of the content items in the root). It's easier to spot these things is you use TypedContent, as you can see in the code completion in (for example) WebMatrix what you'll get back.
So this should work:
Docs for that are here: https://our.umbraco.org/documentation/reference/querying/umbracohelper/#TypedContentAtRoot()
It's better do not use like that :
Better will be as said Sebastiaan - Umbraco.TypedContentAtRoot()
Thanks
If you look at the examples given for .ContentAtRoot() and .TypedContentAtRoot() in Sebastiaans link, they look like this
Giving the impression that .Children is possible, when it is not
I've created an issue to address that.
is working on a reply...