Is there a try-else or similar in Hugo?

I’m running into issues with a dateFormat function failing in cases where I’m already getting a formatted date (instead of UTC or whatever). So I wanted to try to parse the date and if it failed to simply write the string value that’s returned (which is already pretty-printed in the original return value). Is there a Hugo pattern for this?

Answered my own question with a “hack” - basically looking for the “T” in a returned value and then parsing - and if not just writing out the string. Works in all the cases I care about so - WIN!

{{ if in .articlepublished_time "T" }}
        {{ with .articlepublished_time }}{{ dateFormat "Jan 02, 2006" . }} {{ end }}
{{ else }}
        {{ with .articlepublished_time}}{{ . }} {{ end }}
{{ end }}

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