How to get .Page.Lastmod to display only if it's different from created .date?

I want to display last updated on pages that have been updated, but not others.

Here is what I got so far.

  {{- if .Lastmod -}}
  <h4 class="subtitle ml-2">
    Last updated <time datetime="{{ .Lastmod }}">{{ .Lastmod | time.Format ":date_medium" }}</time>
  </h4>
  {{- end -}}

I also tried if isset .Lastmod but it’s always set. I need to do some sort of comparison which I have no idea how to do in hugo templating.

I think I figured it out already.

  {{- if compare.Gt .Lastmod .Date -}}
  <h4 class="subtitle ml-2">
    Last updated <time datetime="{{ .Lastmod }}">{{ .Lastmod | time.Format ":date_medium" }}</time>
  </h4>
  {{- end -}}

{{ if not eq .Lastmod .Date }} is probably more error proof, in case your .Date is after .Lastmod.

1 Like
execute of template failed at <not>: wrong number of args for not: want 1 got 3

:point_down: :point_down: :point_down: :point_down:

{{ if not (eq .Lastmod .Date) }}

{{ if gt .Lastmod .Date }}

more better?

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.