# How to debug a {{ return }} partial

**URL:** <https://discourse.gohugo.io/t/how-to-debug-a-return-partial/55928>\
**Category:** support\
**Created:** [September 16, 2025, 6:54pm UTC](https://discourse.gohugo.io/t/how-to-debug-a-return-partial/55928 "2025-09-16T18:54:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZhenShuo2021](https://avatars.discourse-cdn.com/v4/letter/z/59ef9b/32.png) [@ZhenShuo2021](https://discourse.gohugo.io/u/ZhenShuo2021)\
**Post date:** [September 16, 2025, 6:54pm UTC](https://discourse.gohugo.io/t/how-to-debug-a-return-partial/55928/1 "2025-09-16T18:54:15Z")

</div>

Hello everyone,

I’m trying to debug a partial that uses the `{{ return }}` syntax.

I know that for regular partials, I can use `{{ debug.Dump }}` or `{{ printf "%#v" . }}` to inspect variables, but it seems like these methods don’t work with a partial that only returns a value.

Does anyone have a good method for debugging the value returned by a partial?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![irkode](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/irkode/32/26135_2.png) [@irkode](https://discourse.gohugo.io/u/irkode)\
**Post date:** [September 16, 2025, 8:32pm UTC](https://discourse.gohugo.io/t/how-to-debug-a-return-partial/55928/2 "2025-09-16T20:32:42Z")

</div>

You may use `warnf` to print to the console

keep in mind, that you may only have one return statement, so a typical construct is:

```auto
{{ $result := "" }}
{{ if true }}
  {{ $result = 5 }}
{{ else }}
  {{ $result = 7 }}
{{ end }}
{{ warnf "return value: %s " (debug.dump $result) }}
{{ return $result }}

```

and ofc you may print the returned value directly after the partial call (unless you chain these…

p.s debug.dump works with scalar values, too

a nifty way to display that on a page is:

```auto
{{ highlight (jsonify (dict "indent" " ") $VALUE) "JSON" }}

```

---

<div class="post-metadata">

**Author:** ![ZhenShuo2021](https://avatars.discourse-cdn.com/v4/letter/z/59ef9b/32.png) [@ZhenShuo2021](https://discourse.gohugo.io/u/ZhenShuo2021)\
**Post date:** [September 17, 2025, 5:47am UTC](https://discourse.gohugo.io/t/how-to-debug-a-return-partial/55928/3 "2025-09-17T05:47:48Z")

</div>

I’m working on a partial with multiple if-else statements and return statement because it’s called in several places to process images based on different condition, and I want to check which branch is being executed.

So does this mean that `warnf` is the only way to debug a partial that uses a return statement?

Also, Is there a better approach than relying on a partial with return for this?

---

<div class="post-metadata">

**Author:** ![irkode](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/irkode/32/26135_2.png) [@irkode](https://discourse.gohugo.io/u/irkode)\
**Post date:** [September 17, 2025, 6:01pm UTC](https://discourse.gohugo.io/t/how-to-debug-a-return-partial/55928/4 "2025-09-17T18:01:43Z")

</div>

nothing I am aware of.

the easiest while testing would be to use warnf (maybe combined with a math.Counter and the page and/or template path or remove the return temporarily.

or implement more comples tracing by saving steps in a Store or variable and return both

---

<div class="post-metadata">

**Author:** ![ZhenShuo2021](https://avatars.discourse-cdn.com/v4/letter/z/59ef9b/32.png) [@ZhenShuo2021](https://discourse.gohugo.io/u/ZhenShuo2021)\
**Post date:** [September 18, 2025, 7:53am UTC](https://discourse.gohugo.io/t/how-to-debug-a-return-partial/55928/5 "2025-09-18T07:53:12Z")

</div>

Thank you for your detailed explanation.

I went through the entire documentation again, and it seems that in Hugo the only way to return an object is indeed using return. As you mentioned, the only way to debug is either using `warnf`, returning the object, or save it using `Store` method.

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [September 20, 2025, 7:53am UTC](https://discourse.gohugo.io/t/how-to-debug-a-return-partial/55928/6 "2025-09-20T07:53:58Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
