Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 886 posts 2415 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 886 posts 2415 karma points
    Jun 19, 2019 @ 12:46
    Claushingebjerg
    1

    Ahhh

    Umbraco.ContentAtRoot().FirstOrDefault()
    
  • Bjarne Fyrstenborg 1182 posts 3441 karma points MVP 4x 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

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies