# Howto: Tracing template calls

**URL:** <https://discourse.gohugo.io/t/howto-tracing-template-calls/395>\
**Category:** tips & tricks\
**Created:** [November 30, 2014, 7:28pm UTC](https://discourse.gohugo.io/t/howto-tracing-template-calls/395 "2014-11-30T19:28:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael\_henderson](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/michael_henderson/32/10490_2.png) [@michael\_henderson](https://discourse.gohugo.io/u/michael_henderson)\
**Post date:** [November 30, 2014, 7:28pm UTC](https://discourse.gohugo.io/t/howto-tracing-template-calls/395/1 "2014-11-30T19:28:08Z")

</div>

Hugo uses a set of well-defined rules to determine which template to use to render your content. Still, it’s easy to get confused about what’s happening behind the curtains, so I like to use HTML comments to trace what’s happening. Unfortunately, the Go template strips comments, so you have to use the workaround from the Hugo documentation:

```auto
{{ "<!-- a pithy comment -->" | safeHtml }}

```

Processing the comment as “safeHtml” causes the Go template engine to leave the comment in the output.

To trace my calls, I put `enter` and `leave` comments in my templates and partials. For example:

```auto
{{ "<!-- hugo: enter section/post.html -->" | safeHtml }}
<body> . . . </body>
{{ "<!-- hugo: leave section/post.html -->" | safeHtml }}

```

and

```auto
<!-- hugo: enter partials/banner.html -->
<header role="banner"> . . . </header>
<!-- hugo: leave partials/banner.html -->

```

That makes it easy for me to see the order by looking at the page source in the browser:

```auto
<!-- hugo: enter section/post.html -->
<body>
<!-- hugo: enter partials/banner.html -->
<header role="banner"> . . . </header>
<!-- hugo: leave partials/banner.html -->
<!-- hugo: leave section/post.html -->
</body>

```

When I’m working with a theme, I’ll add the theme’s path to the comments. That helps me see when I’m using something from the theme versus an override from my layouts directory.

```auto
{{ "<!-- hugo: enter theme/zafta/section/post.html -->" | safeHtml }}
<body> . . . </body>
{{ "<!-- hugo: leave theme/zafta/section/post.html -->" | safeHtml }}

```

So far, I haven’t made a conscious effort to put this into all my template files. I add the comments when I run into an issue. I do leave them in when I’m done since they’re so useful.

---

<div class="post-metadata">

**Author:** ![halostatue](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/halostatue/32/62_2.png) [@halostatue](https://discourse.gohugo.io/u/halostatue)\
**Post date:** [December 1, 2014, 7:06pm UTC](https://discourse.gohugo.io/t/howto-tracing-template-calls/395/2 "2014-12-01T19:06:33Z")

</div>

This feels like something that wouldn’t be too hard to add to Hugo as an option, because I’ve wanted the same thing in the past, while developing cabaret.

---

<div class="post-metadata">

**Author:** ![RickCogley](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rickcogley/32/10269_2.png) [@RickCogley](https://discourse.gohugo.io/u/RickCogley)\
**Post date:** [April 27, 2015, 9:11am UTC](https://discourse.gohugo.io/t/howto-tracing-template-calls/395/3 "2015-04-27T09:11:57Z")

</div>

Thanks @michael_henderson, very helpful.

I suppose you could add a debug = “true” to site params in config.toml, and then do a conditional around these to test for that.
