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
Arif
4
{{ if gt .Lastmod .Date }}
more better?
system
Closed
6
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.