Copied to clipboard

Flag this post as spam?

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


  • Koen van Ras 55 posts 315 karma points c-trib
    May 09, 2019 @ 14:32
    Koen van Ras
    0

    Get current IPublishedContent

    Hi,

    I'm trying to get the current IPublishedContent from the contentcache in a logic class. In Umbraco 7 I used to do UmbracoContext.Current.PublishedContentRequest.PublishedContent but this doesn't work in Umbraco 8 anymore. What is the proper way to do this in Umbraco 8?

    Thanks!

  • Carlos Gomes 37 posts 183 karma points
    May 09, 2019 @ 23:22
  • Koen van Ras 55 posts 315 karma points c-trib
    May 13, 2019 @ 08:19
    Koen van Ras
    0

    Hi Carlos,

    In the Sebastiaan's post he shows how to get the content by id, I want to get the current content as IPublishedContent.

    There is no extension method available in UmbracoContext.ContentCache to get this.

  • Harrysoon 32 posts 210 karma points
    May 13, 2019 @ 09:24
    Harrysoon
    3

    You use the Current UmbracoContext in Umbraco.Web.Composing now i.e.

       var content = Current.UmbracoContext.PublishedRequest.PublishedContent;
    
  • Koen van Ras 55 posts 315 karma points c-trib
    Jun 03, 2019 @ 11:59
    Koen van Ras
    101

    I ended up using the UmbracoHelper class using DI.

    protected readonly UmbracoHelper _umbraco;
    
    public DefaultRenderMvcController(UmbracoHelper umbraco)
    {
        _umbraco = umbraco;
    }
    

    And then call the method from the logic file in this controller sending the umbraco helper so I can use it in the logic as: var content = _umbraco.AssignedContentItem;.

  • 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