Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bilal Haidar 144 posts 410 karma points
    Aug 29, 2016 @ 11:42
    Bilal Haidar
    0

    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

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Aug 29, 2016 @ 15:04
    Marc Goodson
    100

    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

  • Bilal Haidar 144 posts 410 karma points
    Aug 29, 2016 @ 18:11
    Bilal Haidar
    0

    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

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Aug 30, 2016 @ 10:31
    Marc Goodson
    1

    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"); }

  • Bilal Haidar 144 posts 410 karma points
    Aug 30, 2016 @ 11:36
    Bilal Haidar
    0

    Thanks a lot Marc. Crystal clear now :)

Please Sign in or register to post replies

Write your reply to:

Draft