Copied to clipboard

Flag this post as spam?

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


  • Robert Freeland 18 posts 90 karma points
    Feb 25, 2021 @ 12:16
    Robert Freeland
    0

    Get Details of Another Content Page

    I am trying to wire up an on published event handler and I need to get the subtitle property value of the currently published item. I cannot seem to get this to work. There has to be an easier way

    Something like:

        public void SendPublishNotifications(Umbraco.Core.Models.IContent publisheditem, string contentClass)
        {
                //publisheditem.Id is my Content Item ID that was published
                //I just want to GET this Content Item and access its Subtitle Property Value
    
        }
    
  • Nik 1517 posts 6705 karma points MVP 5x c-trib
    Feb 25, 2021 @ 13:02
    Nik
    0

    Hi Robert.

    Can you share more of your code? How is that method being called?

    Thanks

    Nik

  • Robert Freeland 18 posts 90 karma points
    Feb 25, 2021 @ 13:45
    Robert Freeland
    1

    I figured this out. This is what I was missing. Appreciate the willingness to assist Nik!!

                var helper = Umbraco.Web.Composing.Current.UmbracoHelper;
                var PublishedPage = helper.Content(publisheditem.Id);
    
  • Nik 1517 posts 6705 karma points MVP 5x c-trib
    Feb 25, 2021 @ 14:01
    Nik
    0

    Hi Robert,

    That's great you got it sorted, but looking at that code and understanding what you said in your initial question, I think you might come up against "strange" errors.

    Using the UmbracoHelper in event handlers etc is not recommended and there are better/more robust ways to get that data.

    Also, using anything off of .Current should be avoided really and instead DI should be taken advantage of.

    Would love to help you get up and running in a more stable approach if you are interested.

    Thanks

    Nik

Please Sign in or register to post replies

Write your reply to:

Draft