Formatting date strings

I’m having trouble formatting date strings in some templates.

I’m trying to use strftime to get article dates formatted for my blog. It works fine when previewing, but it causes the build process to fail with an “undefined method” error.

It’s fine if I leave strftime in the example blog index page, but it kills the build if I use it in a nested template to format page data. For example: <%= current_page.data.date.strftime(’%B %e, %Y’) %>

Am I doing something wrong here? Thanks for helping out a noob.

This is a peculiarity of how middleman-blog works.

current_page.data.date is the string date pulled from the frontmatter of a particular page.
current_page.date is the date object from middleman-blog which can come from either the file path or the frontmatter. Try using this and let me know if it works.

Thanks, for the response. I tried ‘<%= current_page.date.strftime(’%B %e, %Y’) %>’ and I still see the same error when I build. When I run a verbose build, I see messages like this for each article

== Request: /blog/2012/04/30.html
error build/blog/2012/04/30.html
undefined method date' for #<Middleman::Sitemap::Resource:0x007f9bce0b8468> /Users/mvboeke/Dev/mvbsite/source/layouts/article_layout.erb:4:in block (2 levels) in singletonclass’

This is a broader problem than date strings. There appear to be other things that work in the preview server, but fail on build. I’m going to open up a separate thread on the topic.