# How to debug a template?

**URL:** <https://discourse.gohugo.io/t/how-to-debug-a-template/1027>\
**Category:** support\
**Created:** [April 5, 2015, 10:06pm UTC](https://discourse.gohugo.io/t/how-to-debug-a-template/1027 "2015-04-05T22:06:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wyonghao](https://avatars.discourse-cdn.com/v4/letter/w/e9a140/32.png) [@wyonghao](https://discourse.gohugo.io/u/wyonghao)\
**Post date:** [April 5, 2015, 10:06pm UTC](https://discourse.gohugo.io/t/how-to-debug-a-template/1027/1 "2015-04-05T22:06:37Z")

</div>

Hello,  
I am trying to customise homepage or other templates. are there any methods people use to help debug the code? are we simply just rendering the variables in the html outputs and look at them?

Many thanks  
regards

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [April 5, 2015, 10:42pm UTC](https://discourse.gohugo.io/t/how-to-debug-a-template/1027/2 "2015-04-05T22:42:33Z")

</div>

This is helpful:

> **[Howto: show what values are passed to a template](https://discourse.gohugo.io/t/howto-show-what-values-are-passed-to-a-template/41)**
>
> If you ever need to drill into what is passed to a template, just put this at the top of your template somewhere: {{ printf "%#v" . }} Then look at a page generated by that template - that’ll print out what the top level object is, and what it’s...

---

<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:** [April 6, 2015, 2:46pm UTC](https://discourse.gohugo.io/t/how-to-debug-a-template/1027/3 "2015-04-06T14:46:56Z")

</div>

> [@wyonghao](#):
>
> are there any methods people use to help debug the code? are we simply just rendering the variables in the html outputs and look at them?

There’s no general purpose inspector that would allow you to walk up and down the environment stack as Hugo renders the template. So far, there hasn’t been a demand for something like that because Hugo supports “live reloads” of pages.

That feature, which enables your browser to keep in sync with changes to content and templates, makes it easy to modify templates and see the results in almost real time. I know that I’m abusing the term, but it makes using Hugo similar to using a language that has a Read-Eval-Print loop. Debugging consists of interacting with the template via the browser. You save a change and inspect the output in your browser. Hugo’s exposed the Go template’s `printf` function, so you can dump the variable to the browser when something isn’t working.

I admit that debugging via printf isn’t perfect, but Hugo is so fast that it’s very viable.

---

<div class="post-metadata">

**Author:** ![Weston\_McNamee](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/weston_mcnamee/32/540_2.png) [@Weston\_McNamee](https://discourse.gohugo.io/u/Weston_McNamee)\
**Post date:** [July 15, 2015, 5:36am UTC](https://discourse.gohugo.io/t/how-to-debug-a-template/1027/4 "2015-07-15T05:36:35Z")

</div>

Thanks for this tip. It’s great. To add to this, if you have Notepad++, download the JSTool plugin, and copy/paste the content into a new file, then plugins \> JSTool \> JSFormat. You’ll get nice readable data:

```
 & hugolib.Node {
    RSSLink : "http://localhost:1313/index.xml",
    Site : ( * hugolib.SiteInfo)(0xc08245c060),
    Data : map[string]interface {}
    {
        "Pages" : hugolib.Pages {
            ( * hugolib.Page)(0xc08202bc00),
            ( * hugolib.Page)(0xc08202b400),
            ( * hugolib.Page)(0xc0823acc00),
            ( * hugolib.Page)(0xc082167000),
            ( * hugolib.Page)(0xc082166400),
            ( * hugolib.Page)(0xc0821e6000)
        }
    },
    Title : "Test",
    Description : "",
    Keywords : []string(nil),
    Params : map[string]interface {}

    (nil),
    Date : time.Time {
        sec : 0,
        nsec : 0,
        loc : ( * time.Location)(nil)
    },
    Sitemap : hugolib.Sitemap {
        ChangeFreq : "",
        Priority : 0
    },
    UrlPath : hugolib.UrlPath {
        Url : "/",
        Permalink : "http://localhost:1313/",
        Slug : "",
        Section : ""
    },
    paginator : ( * hugolib.pager)(nil),
    paginatorInit : sync.Once {
        m : sync.Mutex {
            state : 0,
            sema : 0x0
        },
        done : 0x0
    },
    scratch : ( * hugolib.Scratch)(nil)
}
```
