Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 939 posts 2574 karma points
    Jun 19, 2019 @ 12:35
    Claushingebjerg
    0

    site root from ipublishedelement

    How do i get the site root from an IpublishedElement.

    Model.Root()
    

    doesnt work as Model is the IpublishedElement

    Compiler Error Message: CS1929: 'IPublishedElement' does not contain a definition for 'Root' and the best extension method overload 'PublishedContentExtensions.Root(IPublishedContent)' requires a receiver of type 'IPublishedContent'

  • Claushingebjerg 939 posts 2574 karma points
    Jun 19, 2019 @ 12:46
    Claushingebjerg
    1

    Ahhh

    Umbraco.ContentAtRoot().FirstOrDefault()
    
  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Jun 19, 2019 @ 12:50
    Bjarne Fyrstenborg
    101

    Hi Claus

    In the view you can access the IPublishedContent via UmbracoHelper (Umbraco) or UmbracoContext.

    var currentNode = Umbraco.AssignedContentItem.Root();
    var site = currentNode.Root();
    

    or

    var currentNode = UmbracoContext.PublishedRequest.PublishedContent;
    var site = currentNode.Root();
    

    https://our.umbraco.com/forum/templates-partial-views-and-macros/94410-get-current-root-node-from-nested-content-partial-view

    You can also use Umbraco.ContentAtRoot(), but with multiple root nodes, you might need to filter it further.

    /Bjarne

Please Sign in or register to post replies

Write your reply to:

Draft