Copied to clipboard

Flag this post as spam?

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


  • Ben Evans 5 posts 85 karma points
    Aug 31, 2017 @ 14:57
    Ben Evans
    0

    Populating simple information labels in the backoffice

    Hi all,

    I'm a little stuck on something I hope someone can help with.

    In our backoffice we have a 'Properties' tab that we can't edit / add to. I've been asked to make an Audit tab that has the following 'Labels' just like our 'Created by' but using different data.

    • Last Updated Date
    • Last Updated Time
    • Last Updated By

    I have made similar things in code to be displayed in pages before, but never to be displayed in the backoffice and I don't know how to populate the labels with the page info.

    Here's what I've used before in content:

    @CurrentPage.UpdateDate.ToString("D")
    @CurrentPage.UpdateDate.ToString("HH.mm")
    @CurrentPage.WriterName
    

    The results of these would be perfect if I could just make the display in the label. Is label even the best thing to use for noEdit data to be displayed?

    Any help or pointers would be much appreciated.

    thanks in advance,

    Ben

  • David Armitage 510 posts 2081 karma points
    Sep 01, 2017 @ 04:46
    David Armitage
    0

    Hi,

    If you are wanting to have read only fields in Umbraco backend and populate them with data then you can use events.

    In your case I would.

    Add 3 labels (Date Updated, Time Updated, Writer Name)

    I would then add an event handler for publishing. To do some extra stuff inside the publishing process.

    Like below. This would set your fields. I guessed the code so please check the correct param names etc. My version is in-accurate but you should be able to figure it out from there.

    public class RegisterEvents : ApplicationEventHandler
    {
            public RegisterEvents()
            {
                ContentService.Published += Published;
                ContentService.Publishing += Publishing;
            }
    
    
            private void Publishing(IPublishingStrategy sender, PublishEventArgs<IContent> args)
            {
                foreach (var node in args.PublishedEntities)
                {
                    if (node.ContentType.Alias == "NODE TYPE ALIAS HERE")
                    {
                        //node.Properties["PROPERTY ALIAS HERE"].Value = node.UpdatedDate.ToString("HH.mm");
                        //eg.
    
                        node.Properties["dateUpdated"].Value = node.UpdatedDate.ToString("D");  //check the correct param name for UpdatedDate - I guessed this
                        node.Properties["timeUpdated"].Value = node.UpdatedDate.ToString.ToString("HH.mm"); 
                        node.Properties["writerName"].Value = "WHAT EVER YOU WANT";
                    }
                }
            }
    }
    

    Kind Regards

    David

  • Ben Evans 5 posts 85 karma points
    Sep 04, 2017 @ 10:43
    Ben Evans
    0

    Hi David,

    Thanks for the help, I'll get on it today and let you know how I get on - I may have to do a little reading on adding the event handler!

    thanks again

    Ben

Please Sign in or register to post replies

Write your reply to:

Draft