Copied to clipboard

Flag this post as spam?

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


  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Aug 08, 2017 @ 16:40
    Nik
    0

    Accessing IPublishedContent in ContentService.Published event

    Hi All,

    Hoping you can help/point me in the right direction. I'm hooking into the ContentService.Published event but I'm trying to access the IPublishedContent equivalents of the IContent.

    I have the following:

    if(args.PublishedEntities != null)
    {
        foreach(var publishedEntity in args.PublishedEntities)
        {
             //I want to do some bits here
        }
    }
    

    What I'm trying to do is much easier if I can get the IPublishedContent for my IContent, however when I try and use an instance of UmbracoHelper to do .TypedContent passing in the key from the IContent it is returning null.

    If I cannot get the IPublishedContent from IContent, what is the best way to find the root node of an IContent and also handle children and property access?

    Steven mentioned the following in Slack:

    umbraco.content.AfterUpdateDocumentCache
    

    however this doesn't seem to fire after the cache has been updated in that the IPublishedContent still doesn't come back from TypedContent and looking at the umbraco.config file it's still missing the newly published entry.

    Has anyone got any ideas that can help?

    Cheers,

    Nik

  • Marcio Goularte 374 posts 1346 karma points
    Aug 08, 2017 @ 18:00
    Marcio Goularte
    101

    try this:

    var content = UmbracoContext.Current.ContentCache.GetById(publishedEntity .Id);

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Aug 09, 2017 @ 08:22
    Nik
    0

    Thanks Marcio, that seems to be the way to get it. You're a star, thanks!

Please Sign in or register to post replies

Write your reply to:

Draft