CommunityServer date format hacking
I love the CS skinning model, but sometimes it’s difficult to get at
the formatting of certain controls. The nifty date format I have here
on this blog required a bit of a “hack” to work since the date
formatting is hard coded into the CS source code. I could’ve modified
the source to do this, but I wanted to use the skinning model. In the
file \cs1.0_src\Blogs\Controls\EntryView.cs line 67, you find this code:
EntryDesc.Text = string.Format("posted on {0}",DataSource.BloggerTime.ToString("f"));
I wanted to modify the formatting from the default “f” to something
else. Thankfully ASP.NET’s event model and slick date parsing makes
this super easy. I just modified
\cs1.0\web\Themes\Blogs\MyGreatSkin\Skins\Skin-EntryView.ascx to
include on OnPreRender event (quick note: Page_XXX methods don’t need
the method signature):
<script runat="server">void Page_PreRender() { string dateString = EntryDesc.Text.Replace("posted on ",""); DateTime realDate = DateTime.Parse(dateString); EntryDesc.Text = string.Format( "<span class=\"postdate-dow\">{0}</span>" "<span class=\"postdate-day\">{1}</span>" + "<span class=\"postdate-monthyear\">{2}</span>", realDate.ToString("ddd"), realDate.ToString("dd"), realDate.ToString("MMM yy") );}</script>
That’s it!