I want each page to show its creation date, but only if I have set a date in the front matter.
My content file has:
date: “2015-08-15”
And in my _default/single.html template:
{{ if eq .Type “page” }}
{{ if isset .Date }}
{{ .Date.Format “Monday, Jan 2, 2006” }}
{{ end }}
{{ end }}
Apparently {{ if isset .Date }} is not the correct syntax. What should I use instead?
spf13
2
Date is always set. May be better to say after a certain date.
bep
3
Try:
{{ if not .Date.IsZero }}
Date is never nil
– but it has a zero value if not set.
2 Likes
Thanks! That works perfectly, and it’s more elegant than the alternatives I was thinking about.
jmooring
Split this topic
6