Mephisto Tidbit #1 - Formatting Dates
March 1st, 2007
There may come a time with your Mephisto installation that you want to change the way that the dates are displayed on your blog. Or maybe you are a designer working on an ultra-cool template that needs a funky date format. This is how you work with date formats.
Standard Date Format with Simpla
The default Simpla theme for Mephisto (the one my blog is using currently) displays the date using the mdy format like so:
<h3>{{ article.published_at | format_date: 'mdy', true }}</h3>
So what if you want to use a different format? What do you use instead of mdy? If you are adventurous, peer into the file mephisto_init.rb in the lib directory.
:standard => '%B %d, %Y @ %I:%M %p', :stub => '%B %d', :time_only => '%I:%M %p', :plain => '%B %d %I:%M %p', :mdy => '%B %d, %Y', :my => '%B %Y'
Here’s a list of date formats you can use besides the standard ones that come with Rails, which are.
:db => "%Y-%m-%d %H:%M:%S", :short => "%d %b %H:%M", :long => "%B %d, %Y %H:%M", :rfc822 => "%a, %d %b %Y %H:%M:%S %z"
2 Responses to “Mephisto Tidbit #1 - Formatting Dates”
Sorry, comments are closed for this article.
March 8th, 2007 at 01:38 PM IMO, changes shouldn't be made to the mephisto files to avoid conflicts on updates. Also, they might be a better fit for your environment.rb if you really want them permanent. But, if you're developing a theme or just don't want to edit mephisto files you could use the strftime filter: {{ article.published_at | strftime: '%Y-%m-%d %H:%I' }}
March 21st, 2007 at 06:57 PM I feel remiss in not replying to this fantastic comment sooner. All I have to say though is... Thanks! That's great info that really adds value. So, to all future readers of this article - __peer into__ the @mephisto_init.rb@ file to see what it does, but don't make any changes there. :)