HUGO

Server option to output templates used?

I noticed a few posts on the forums and elsewhere that people (me included) have need for explicit confirmation for which templates have been used for output. Most solutions out there seem to hack existing Hugo functionality to do this if required.

I am wondering if the need for confirmation of templates used is a need ubiquitous enough that it should be formalised? Off the top of my head I can think of a couple options that might satisfy this possible need:

  1. Flag that tells Hugo Server to output an additional HTML page that summarises the templates used by all rendered pages. Or if not an HTML page then maybe HTML comments within each rendered page.
  2. If someone has created a clean and robust enough solution (pieced together from existing Hugo functionality) then maybe it could be integrated into Hugo for a wider audience?

I just thought I would post this as a finger in the wind test to see what people think and how they might have addressed the need.

1 Like

I was making a theme component at one point around this idea.

Essentially add a .Scratch var to layout files of interest, then create a tree of the partials and layouts used.

I got as far as printing the following output to the browser console:

  <baseof>
    <head.html>
      <head /css.html> </head /css.html>
      <head /meta.html> </head /meta.html>
    </head.html>
    <header.html> </header.html>
    <layouts /index.html>
      <utils /foo.html> </utils /foo.html>
      <utils /bar.html> </utils /bar.html>
    </layouts /index.html>
    <footer.html> </footer.html>
  </baseof>

based on a layout folder like this:

layouts
├── 404.html
├── _default
│   ├── baseof.html
│   ├── list.html
│   └── single.html
├── index.html
└── partials
    ├── footer.html
    ├── head
    │   ├── css.html
    │   └── meta.html
    ├── header.html
    ├── head.html
    └── utils
        ├── bar.html
        ├── baz.html
        └── foo.html

I’ll see if I can do some more work on it next weekend or so. Apparently I haven’t touched it since last year, so thanks for reminding me :sweat_smile:

1 Like

Nice :slight_smile: I am doing it via printf of the current filename into an HTML comment manually added to all templates. On production the comments get removed by minification.

Yes.

https://discourse.gohugo.io/t/2361
https://discourse.gohugo.io/t/5292
https://discourse.gohugo.io/t/7660
https://discourse.gohugo.io/t/10168
https://discourse.gohugo.io/t/11507
https://discourse.gohugo.io/t/12893
https://discourse.gohugo.io/t/15317
https://discourse.gohugo.io/t/17691
https://discourse.gohugo.io/t/20320
https://discourse.gohugo.io/t/26059

https://github.com/gohugoio/hugo/issues/1736 [closed]
https://github.com/gohugoio/hugo/issues/2609 [opened 19 Oct 2016]
https://github.com/gohugoio/hugo/issues/3514 [closed by stalebot]
https://github.com/gohugoio/hugo/issues/5453 [closed by stalebot]
https://github.com/gohugoio/hugo/pull/5452 [closed by stalebot]

And there are probably more.

2 Likes