Handlebars helpers for today's date inside a post object

I’m wondering if there is a way to use {{date}} to post the current date while inside a post loop. The docs indicate that the current date will only be used if there’s no ‘published_at’ property (i.e. you aren’t inside a post object). Is there a specific value I can pass the date handler to indicate that I want the current date even when I’m inside a post object?

You should be able to pass an empty string - i.e. {{date ""}}

This does work to get the current date but only in the default format (e.g. ‘Jul 21, 2021’). If you need it in a specific format unfortunately it does not work.

Right, you would need to add the format option - {{date "" format="MM YYYY"}}

Sorry I wasn’t clear. I meant, when you add the format option with no other parameter, it seems to automatically assume you are referring to the published_at value if none is provided and you are within a post object.

That is correct, can you clarify what you’re not sure about here?

I need the current date to be output to a section of the page of a post. It happens to be within the post object. Because of this, I can’t use the {{date}} handlebar object to get the current date unless I don’t specify the format. But, I need it in a specific format. My question is whether there is a value I can use to specify getting the current date with the {{date}} handlebar object while also specifying a format.

This should work:

Oh okay I see. I did not realize there was a difference between missing value and empty string. e.g.

{{date "" format="MM YYYY"}} 

and

 {{date format="MM YYYY"}}

Thanks :slight_smile:

1 Like