Display modified date on posts template

Hi everyone,

How can I display the modified date of a post if the created date is different of the modified date?

Best regards

Hey @Bruno_Sousa :wave:
The post object contains an updated_at value which is exposed in the handlebars theme #post context. Editing the post.hbs and adding {{updated_at}} helper should do the trick. More info can be found here:

Hi @DavidDarnes,

I tested that, but If the post is not modified the created date is the same as modified date. How can I check if the modified date is not the same as created date?

Best regards

That’s where some clever CSS can come in handy:

<style media="screen">
  .updated[datetime="{{published_at}}"] { display: none; }
<time class="updated" datetime="{{updated_at}}">Updated: {{updated_at}}</time>
<time class="published" datetime="{{published_at}}">Published: {{published_at}}</time>

The CSS here is selecting the updated date element with an attribute value of the published date and hiding it, it’ll only appear if the updated date is different to the published date :+1:

1 Like

Hi @DavidDarnes,

Thanks for your help, it worked!
Do you know if it’s possible to compare just the date instead of datetime?

Best regards,

I’m not sure what you mean? I used the datetime attribute as that’s a semantic attribute of the <time> element. Could you be more specific?