Getting the name of the template or partial for debugging/tracing

I’m currently putting comments at the top of my partials to help me figure out where chunks are coming from:

{{ "<!-- hugo: enter skeleton/partials/banner.html -->" | safeHTML }}

After typing it dozens and dozens of times, I’m starting to think that it would be nicer to just call a function, something like {{ .TemplateName }} instead of typing in the path + name myself. I’m finding that when I clone templates, I forget to update that comment.

Is there an existing function that returns the name of the current template? Name with path, relative to the site root, would be ideal.

If there is, the next question is how to embed multiple mustache levels? Is it possible with Go templates or must I split it up like:

{{ "<!-- hugo: enter " | safeHTML }}{{ .TemplateName }} {{ " -->" | safeHTML }}

Now that I’m thinking about it, it would be nice to have an option to have Hugo automatically add that text before and after every template call.

Edit: Added Issue #1736 for this.

No. It’s a good idea, but I don’t think it’s possible (or easy) to add either.

2 Likes

Yeah. I looked into the code this morning and the template name isn’t readily available.

As a side note, this time around it only took me 45 minutes to remember that while I was making changes in GOROOT/github.com/mdhender/hugo, it was really building from GOROOT/github.com/spf13/hugo. I think I need to put together all the notes that I have on how to work on Hugo.

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