This project is read-only.

Best way to customize published date display ?

Topics: General, Writing themes
May 9, 2012 at 3:54 PM

I'm trying to find the best (recommended) way to customize the published state date of a content item.

I only want to remove the datetime part of the published date in my theme.

It seems that I must override Parts.Common.Metadata.cshtml template in my theme then code again the Shapes.PublishedState and the DateTime.Display core shapes behavior.

It ends with this code in my Parts.Common.Metadata.Summary.cshtml :

<div class="published">
    @if (!((DateTime?)Model.ContentPart.PublishedUtc).HasValue) {
    } else {
        @Display.DateTime(DateTimeUtc: Model.ContentPart.CreatedUtc, CustomFormat:T("dd MMMM yyyy"));

Could this code be better ? For example, I have now to maintain a copy of the "Draft" resource translated for my theme, and the published state behavior is coded in my theme instead of relying on the default behavior.

May 9, 2012 at 5:46 PM

I don't see a problem with that. Themes are there to enable you to override the default rendering, which seems to be exactly what you are doing here.

Jun 6, 2012 at 8:49 AM

I just wanted to be sure I was not missing something.