RecentBlogPosts getting the PublishedUtc or Created date...

Topics: Customizing Orchard
Dec 7, 2012 at 9:07 PM

I'm looking for some guidance as to how to get one or both of these dates so I can do some custom formatting of the RecentBlogPosts widget within an alternate.  I followed the guidance of:

http://weblogs.asp.net/bleroy/archive/2011/03/27/taking-over-list-rendering-in-orchard.aspx

and everything pretty much works except I just can't seem to gain control over showing a date.  I thought I could just use the PublishedUtc of the BlogPost model but it always comes back null along with the Title which I am guessing is not right since it's used in the example post above. 

Any guidance is appreciated...

Dec 7, 2012 at 9:44 PM
Edited Dec 7, 2012 at 9:45 PM

And naturally as soon as I post this I was able to solve my own answer.  I was attempting to use a shape as a part.

Dec 7, 2012 at 10:06 PM
Edited Dec 7, 2012 at 10:13 PM

I'm not sure why the original blog post from Bertrand has a "post.Title" but this was what I had to do to get what I wanted out of the RecentBlogPost alternate...

 

@{
    IEnumerable<object> blogPosts = Model.ContentItems.ContentItems;
}
@if (blogPosts == null || blogPosts.Count() < 1) {
<p>@T("No posts.")</p>
}
else {
    <ul class="no-list news-list">
    @foreach (dynamic post in blogPosts) {
        string title = post.ContentItem.TitlePart.Title;
        DateTime date = post.ContentItem.CommonPart.CreatedUtc;
        string dayStr = date.ToString("dd");
        string monthStr = date.ToString("MMM").ToUpper();
        
        <li class="content-item-summary">
            <div class="news-list-date">
                @dayStr<span>@monthStr</span>
            </div>             
            <div class="news-list-content">
                @Html.ItemDisplayLink(title, post.ContentItem)
          </div>   
        </li>
    }
    </ul>
}
Dec 7, 2013 at 3:35 AM
Thanks for posting your solution...I've been playing around for the past hour and couldn't figure out how to get to the created date.