How to access nodes when there is more than 1 root
Hello all
I'm having trouble getting the code right to list the nodes as shown in the image.
I did have the Events Organiser as a child in Home but had to move it out when our site went bilingual. Previous code that worked when it was contained in Home is below.
var selection = Model.Content.Site().FirstChild("eventsAdmin").FirstChild("eventHolder").Children("event").where .....
But how should I tweak that to get the same result?
You have a few options, however the easiest in my opinion would be add a property on to your home page document type where you select the events container node.
Then you can do the following:
var site = Model.Content.Site();
if(site.HasValue("eventContainerNode"))
{
var eventsContainer = Umbraco.TypedContent(site.GetPropertyValue("eventContainerNode"));
if(eventsContainer != null)
{
var events = eventsContainer.Children("event");
}
}
This also gives you scope for having language specific events if you need it.
Another option is to utilise Examine to get the events, that way you can filter them by up coming ones, assuming they have a date on them, as well and exclude past ones if needed.
Model.Content.Site or Model.Content.AncestorOrSelf(1) goes from the node you are on to the node at level 1 (the root) so you cannot go to another rootnode
Umbraco.TypedContentAtRoot() gives you all root nodes in the umbraco.
so to get the (first) events organiser from anywhere you can do
As a remark:
If you go this approach, having 1 section (repository) for All your events over multiple languages, then it might be a good idea to wrap the properties on the events in Vorto properties. This way you can make them multilingual as well.
How to access nodes when there is more than 1 root
Hello all
I'm having trouble getting the code right to list the nodes as shown in the image.
I did have the Events Organiser as a child in Home but had to move it out when our site went bilingual. Previous code that worked when it was contained in Home is below.
But how should I tweak that to get the same result?
Hi David,
You have a few options, however the easiest in my opinion would be add a property on to your home page document type where you select the events container node.
Then you can do the following:
This also gives you scope for having language specific events if you need it.
Another option is to utilise Examine to get the events, that way you can filter them by up coming ones, assuming they have a date on them, as well and exclude past ones if needed.
Nik
Hey david
Model.Content.Site
orModel.Content.AncestorOrSelf(1)
goes from the node you are on to the node at level 1 (the root) so you cannot go to another rootnodeUmbraco.TypedContentAtRoot()
gives you all root nodes in the umbraco.so to get the (first) events organiser from anywhere you can do
So to complete your example
As a remark: If you go this approach, having 1 section (repository) for All your events over multiple languages, then it might be a good idea to wrap the properties on the events in Vorto properties. This way you can make them multilingual as well.
Thanks guys some good suggestions there.
is working on a reply...