Extract Blog-Post Date

Topics: General
Dec 11, 2011 at 8:22 AM

I'm trying to change the appearance of the month and day parts of the blog-post metadata.  To do this, I used the shape tracer and found the template to override is "~/Core/Contents/Views/Content.cshtml".  So I copied it to my theme and made the following alteration within the <header> portion of that template:

        @if (Model.Meta != null) {
            string[] monthText = new string[] {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
            var datetext = @Display(Model.Meta);
            DateTime date = DateTime.Parse(datetext.ToString());
            <div class="post-date">
                <span class="entry-month">@monthText[date.Month-1]</span>
                <span class="entry-day">@date.Day</span>

        @if (Model.Meta != null) {
        <div class="metadata">

Well, it didn't work - because the datetext.ToString() returns not merely a date, but a bulk of html that looks like this:

<script class="shape-tracing-wrapper" shape-id="2" shape-type="Parts_Common_Metadata" shape-hint=""></script><div class="published"> <script class="shape-tracing-wrapper" shape-id="3" shape-type="PublishedState" shape-hint=""></script>Dec 6 2011 10:17 PM<script class="shape-tracing-wrapper" end-of="3"></script> </div><script class="shape-tracing-wrapper" end-of="2"></script> ;

So this represents my first problem: how to fetch the date information without all the extra material.  But even if that had worked, I couldn't help but notice that the shape tracer didn't seem to point me at the right template.  The above template controls blog rendering, rather than blog-post rendering.  As I fiddled with the template, the blog-post entries remained entirely unaffected, while the overall blog title area reacted according to my adjustments.  What did I miss?

Again, I just want my blog-post entries to render the blog-post date in such a way that I can apply fine-controlled markup via CSS.

Dec 11, 2011 at 8:44 AM

Oh wow, that's very very wrong :)

OK, so first Content is not the template you want to override. That's too high. You need the template that renders the meta data. Content is only rendering zones into which part templates are going to be rendered.

Then, Model.Meta is a zone, not the meta data part. So yes, when you do display on it, you get the html that it would render.

Finally, there are enough date time APIs in .NET (that are localized) that you won't need to create your own list of month name abbreviations or anything of the sort. Look for datetime format strings in MSDN.