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:


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?

Hi, Thanks for this advice. It works. However the date/time is shown in full ISO format. It appears that neither updated_at nor published_at accept the format property that date does. I’ve had to put them on their separate lines, but it doesn’t look good at all :frowning:


Am I doing something wrong?

Probably. The date helper accepts published_at and updated_at as values. You can use the format attribute with these.

1 Like

Thanks for your super-prompt response :slight_smile:

Yes, worked perfectly. I couldn’t find font icons, so have used BoxIcons using code injection.

Thanks so much.

Next step is to figure out how to exclude updated_at if it is the same date as published_at.