Printing debug information from Hugo templates to the terminal
The warnf and errorf functions print information to the terminal that’s running hugo server:
{{ warnf "Debug: .LinkTitle = %v" .LinkTitle }}
{{ warnf "Debug: context = %#v" . }}
warnf prints a warning message, errorf prints an error and stops the build. These are (I think)
Hugo functions, not Go functions. But they’re based on the Go fmt package.
Useful formatting verbs:
%v- Default format (good for most things)%#v- Go-syntax representation (shows the full structure)%s- String%T- Type of the value
References
Hugo Documentation. “fmt.Warnf.” March 5, 2025. https://gohugo.io/functions/fmt/warnf/.
Go Documentation. “fmt.” December 2, 2025. https://pkg.go.dev/fmt.