How to see which template file is responsible for the output?

Hi there!

I come from the Drupal world, where you can use a tool to add HTML comments to the output indicating which template is responsible for which output on the page. Is there a known technique for doing something like this in Hugo? As is, it feels like a bit of a shot in the dark to dig up the right template and that would only get more difficult with more complex sites.

Thank you!
Chris

I can’t think of a tool but I’d just follow the hierarchy chart for templates in Docs. I remember browsing the Drupal Theming Docs once and there was this HUGE diagram of all the possible theme templates that might be used.

Maybe we can create something like that as a resource.

From what I’ve read, because Hugo is compiled there isn’t any real way to slip some logic into the build process, but I was curious if Hugo had any event listener / hook-style features I didn’t know about, so I could, for instance, append an HTML comment to the end of each template upon build if there was a ‘debug-templates: true’ in the config.

Anything that might support that? If not, I know I could just make a point of manually adding these, but that’s a lot of unnecessary repetition that would be nice to avoid.

to @chrisshattuck and @FelicianoTech I came up with this idea a while ago:

Maybe it’ll work for you. it does mean touching each template file, but that way you know what gets rendered where.

1 Like