CommunityServer date format hacking

June 4, 2005 | Uncategorized | Comments Off on 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 =
"<span class=\"postdate-dow\">{0}</span>"
"<span class=\"postdate-day\">{1}</span>" +
"<span class=\"postdate-monthyear\">{2}</span>",
realDate.ToString("MMM yy")

That’s it!

Comments are closed.

Hi, I'm John Dyer. In my day job, I build websites and create online seminary software for a seminary in Dallas. I also like to release open source tools including a pretty popular HTML5 video player and build tools that help people find best bible commentaries and do bible study. And just for fun, I also wrote a book on the theology of technology and media.

Fork me on GitHub

Social Widgets powered by