Error after update on Windows, dateFormat

Just updated Hugo to the latest version from a much earlier version. There’s this error with the dateFormat (original output has proper url)

Error: Error building site: failed to render pages: render of "page" failed: execute of template failed: template: _default/single.html:17:8: executing "main" at <partial "post-meta" .>: error calling partial: ...\layouts\partials\post-meta.html:4:111": execute of template failed: template: partials/post-meta.html:4:111: executing "partials/post-meta.html" at <dateFormat "Jan 2, 2006" .Params.Show_date>: error calling dateFormat: unable to cast <nil> of type <nil> to Time

That’s from this code, which I had customized along the way and was working in the old version

{{if .Date}}{{- .Date.Format "Jan 2, 2006" -}}{{ else }}{{- dateFormat "Jan 2, 2006" .Params.Show_date -}} {{ end }}

Does anyone know the quick fix here?

(Also, I’ve only been coding for about 7 years, so if you could keep it simple that would be great :pray: )

It appears that a page in your project does not have a date and Hugo complains about it.

The way to write Go templates is by wrapping everything within a condition. However if does not escape a code block if a variable is absent and that is probably why you are encountering this error.

Instead of if use with, that does escape a code block and rebinds the context. Have a look about it at:

Also read about the concept of context over here: https://gohugo.io/templates/introduction/#the-dot

However if the error persists then you will have to share your project for us to see what is going on.

I see. Thanks. With is good way to select what’s in the loop. This was earlier an attempt at fixing incorrect date entry - left in place as backup but anyway invalid and now on version update showing error. Removing if an else conditions works here. Thanks again.