Best way to customize published date display ?

Topics: General, Writing themes
May 9, 2012 at 2: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) {
        @T("Draft");
    } else {
        @Display.DateTime(DateTimeUtc: Model.ContentPart.CreatedUtc, CustomFormat:T("dd MMMM yyyy"));
    }
</div>

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.

Coordinator
May 9, 2012 at 4: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 7:49 AM

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

Thanks!