I cannot find the property Site() on the CurrentPage in the documentation. What's this property and where it is defined? Can I use it on any page in the hierarchy?
the Site() property on the DynamicPublishedContent item
is 'shorthand' for
AncestorOrSelf(1)
Which means traverse all the way up the content tree until you find a page at level 1 (eg the top of the site) and if you are already on that page then use that....
So you can use it on any page template in the hierachy and it will always refer to your top most page in the tree, which usually is your site homepage, and that may contain other 'site wide' properties, which is where the name has sort of come from.
How about having more than root? For instance, I might have Home root + a Settings Content Item (with all global configurations). Would I be able to access the Settings Content Item using this property?
@{
// get all rootNodes, Home and Settings
var rootNodes = Umbraco.ContentAtRoot();
// or use Xpath
var settingNode = Umbraco.ContentSingleAtXPath("//settingsdoctypealias");
}
What is @CurrentPage.Site()?
Hi,
I cannot find the property Site() on the CurrentPage in the documentation. What's this property and where it is defined? Can I use it on any page in the hierarchy?
Thanks
Hi Bilal
the Site() property on the DynamicPublishedContent item
is 'shorthand' for
AncestorOrSelf(1)
Which means traverse all the way up the content tree until you find a page at level 1 (eg the top of the site) and if you are already on that page then use that....
https://github.com/umbraco/Umbraco-CMS/blob/c4400a20d6ae9df6faac4756050905ba7228d579/src/Umbraco.Web/Models/DynamicPublishedContent.cs
So you can use it on any page template in the hierachy and it will always refer to your top most page in the tree, which usually is your site homepage, and that may contain other 'site wide' properties, which is where the name has sort of come from.
regards
Marc
Many thanks Marc.
How about having more than root? For instance, I might have Home root + a Settings Content Item (with all global configurations). Would I be able to access the Settings Content Item using this property?
Thanks
Site() will just get you the top node in the current tree at level 1
So it depends where your seperate settings node sits to allow you to traverse to it:
eg if you have
Home - Settings - Content
then Site() on a content page would would refer to Home and ancestororself(2) would refer to Settings
but if Settings is alongside Home at the same level in the tree eg
Home - Content Settings - Other Settings
then Site() on a content page would refer to Home, to get to the settings you could use the Umbraco Helpers:
https://our.umbraco.org/documentation/reference/querying/umbracohelper/
@{ // get all rootNodes, Home and Settings var rootNodes = Umbraco.ContentAtRoot(); // or use Xpath var settingNode = Umbraco.ContentSingleAtXPath("//settingsdoctypealias"); }
Thanks a lot Marc. Crystal clear now :)
is working on a reply...