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.
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?
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";
}
}
}
}
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.
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:
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
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.
Kind Regards
David
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
is working on a reply...