What are your techniques for debugging Go templates/shortcodes?

I’m wondering what the communities techniques are for debugging Go templates and Hugo shortcodes.

Is there a way to test Go specific parts of the code in some kind of Go REPL? Or to run the code somehow and see the output?

What I’ve been doing is testing outputs by writing it in a template and using the liveserver to see what the output is, or if the server reports an error. Pretty hacky but I don’t know of another way. Especially with complicated conditional or looping or comparative operations in shortcodes.

There are others on the forum that know more about this, but you can use variations of {{ printf "%#v" . }}

1 Like