09 November, 2009

Using commas in your SilverStripe templates.

I just had this problem when formatting dates of the SilverStripe Blog module on a new website project. Its true that you can do this by $Date.Format(d-m-Y) type of syntax. But what I needed was to add a comma to the date so the date was supposed to read like 09 November, 2009. To get this on the pages I had to use $Date.Format(d F, Y) type of thing. But unfortunately the SilverStripe's template parser doesn't allow commas.

There was a patch but I was running out of time, and didnt have much time to go through them. So as a quick fix I added the HTML escape character of the comma to the argument which is ,. Now this worked for me.

My code was

$Date.Format(d F, Y)

Check it out, it can be useful for you to work with SilverStripe Dates.

No comments: