Printing template lookup order and chosen template

Is there anyway to print the current template being used for a page? I think this would really help with debugging.

I can see when i run the server in debug mode ie hugo serve --debug I do see the template lookup order and possible matches but I don’t see the chosen template. I’d like to get this information (primarly chosen template, but lookup order would be very nice) into a variable I can print out in the browser.

I don’t know of a way to do this (if it’s possible, I’d like to know how as well).
In the past I’ve resorted to putting debug statements in each template that get printed whenever that template is used.

This is what I do as well, but it’s laborious and error prone.

I really think that one of Hugos strength is it’s stricter content and layout paradigm. But at the same time it isn’t immediately intuitive and can lead to a lot of frustration when trying to create pages and hook them into the correct templates.

I imagine most new Hugo users can relate to the process of randomly moving and renaming markdown and layout files until you find a ‘match’. Even after you’ve got it working, you are most likely still baffled by the magic of the templating system and quickly tell yourself "next time i’ll figure it out properly’

More developer tools to surface the lookup order and how different content structures map to the layouts would be a huge win for Hugo.

1 Like