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 56 posts 361 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 38 posts 184 karma points
    May 09, 2019 @ 23:22
  • Koen van Ras 56 posts 361 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.

  • Harrison 42 posts 254 karma points
    May 13, 2019 @ 09:24
    Harrison
    4

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

       var content = Current.UmbracoContext.PublishedRequest.PublishedContent;
    
  • Koen van Ras 56 posts 361 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;.

Please Sign in or register to post replies

Write your reply to:

Draft