# Unmarshal fails when called from a partial template in a content adapter

**URL:** <https://discourse.gohugo.io/t/unmarshal-fails-when-called-from-a-partial-template-in-a-content-adapter/57583>\
**Category:** support\
**Created:** [September 24, 2026, 2:27pm UTC](https://discourse.gohugo.io/t/unmarshal-fails-when-called-from-a-partial-template-in-a-content-adapter/57583 "2026-09-24T14:27:16Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![abrusle](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@abrusle](https://discourse.gohugo.io/u/abrusle)\
**Post date:** [September 24, 2026, 2:27pm UTC](https://discourse.gohugo.io/t/unmarshal-fails-when-called-from-a-partial-template-in-a-content-adapter/57583/1 "2026-09-24T14:27:16Z")

</div>

I am working on a project where most of the content lives in a database behind a self-hosted CMS, and I would like to generate static pages from my CMS’ api through content adapters.

In order to reuse the logic for handling requests (building the requests & handling errors), I have tried setting up a [partial template to be called from `_content.gotmpl`](https://discourse.gohugo.io/t/how-to-modularize-go-templates-and-reuse-them/54434), but am encountering this error:

```auto
ERROR error building site: process: readAndProcessContent: "[...]/temp-hugo/content/_content.gotmpl:8:46": template: [...]/temp-hugo/content/_content.gotmpl:8:46: executing "[...]/temp-hugo/content/_content.gotmpl" at <partial "my-partial" .>: error calling partial: "[...]/temp-hugo/layouts/_partials/my-partial.html:3:23": execute of template failed: template: _partials/my-partial.html:3:23: executing "_partials/my-partial.html" at <transform.Unmarshal>: error calling Unmarshal: type *pagesfromdata.pagesFromDataTemplateContext not supported

```

Here’s a minimal setup that reproduces the error, with some logs to compare request made from `_content.gotmpl` with request made from the partial template:

> **content/\_content.gotmpl**
>
> ```auto
> {{ warnf "[content] %s" site.Params.endpoint }}
> 
> {{ with resources.GetRemote site.Params.endpoint }}
> {{ warnf "[content] res: %v" (debug.Dump .) }}
> {{ warnf "[content] obj: %v" (debug.Dump ( transform.Unmarshal . )) }}
> {{ end }}
> 
> {{ warnf "[content] result from partial: %v" (partial "my-partial" .) }}
> 
> ```

The request + unmarshalling succeeds in the content adapter, but fails when called from the partial.

> **layouts/\_partials/my-partial.html**
>
> ```auto
> {{ with resources.GetRemote site.Params.endpoint }}
> {{ warnf "[my-partial] res: %v" (debug.Dump .) }}
> {{ return transform.Unmarshal . }}
> {{ end }}
> 
> ```

The endpoint here is just a [mockbin.io](http://mockbin.io) url that returns `{"message": "Hello World"}`.

I am probably doing something wrong, or perhaps this way of using content adapters is not currently supported?

---

<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:** [September 24, 2026, 4:33pm UTC](https://discourse.gohugo.io/t/unmarshal-fails-when-called-from-a-partial-template-in-a-content-adapter/57583/2 "2026-09-24T16:33:12Z")

</div>

> [@abrusle](#):
>
> I am probably doing something wrong, or perhaps this way of using content adapters is not currently supported?

No, that should be perfectly fine. I don’t see anything wrong with your setup, which suggests that there’s something I don’t see.

---

<div class="post-metadata">

**Author:** ![abrusle](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@abrusle](https://discourse.gohugo.io/u/abrusle)\
**Post date:** [September 24, 2026, 4:59pm UTC](https://discourse.gohugo.io/t/unmarshal-fails-when-called-from-a-partial-template-in-a-content-adapter/57583/3 "2026-09-24T16:59:43Z")

</div>

Oh right, if you want to look into it, here’s a repo with the full minimal setup: [abrusle/sharing-hugo-issue - Codeberg.org](https://codeberg.org/abrusle/sharing-hugo-issue)

Just set the endpoint url in `hugo.yaml` and then build the site.

---

<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:** [September 24, 2026, 5:08pm UTC](https://discourse.gohugo.io/t/unmarshal-fails-when-called-from-a-partial-template-in-a-content-adapter/57583/4 "2026-09-24T17:08:32Z")

</div>

What Hugo version do you build with?

---

<div class="post-metadata">

**Author:** ![abrusle](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@abrusle](https://discourse.gohugo.io/u/abrusle)\
**Post date:** [September 24, 2026, 5:31pm UTC](https://discourse.gohugo.io/t/unmarshal-fails-when-called-from-a-partial-template-in-a-content-adapter/57583/5 "2026-09-24T17:31:37Z")

</div>

Thank you for taking the time to help, really appreciate 🙂

I’m using hugo v0.162.1, the latest provided by my distro’s package manager.

---

<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:** [September 24, 2026, 5:37pm UTC](https://discourse.gohugo.io/t/unmarshal-fails-when-called-from-a-partial-template-in-a-content-adapter/57583/6 "2026-09-24T17:37:09Z")

</div>

> [@abrusle](#):
>
> I’m using hugo v0.162.1, the latest provided by my distro’s package manager.

Yea, OK, then I think I know what it is (even if the error you describe is mysterious)🙂

- Your demo site works with the latest Hugo.
- We rewamped the return keyword in v0.166.0 (see [Release v0.166.0 · gohugoio/hugo · GitHub](https://github.com/gohugoio/hugo/releases/tag/v0.166.0))
- In older Hugo versions, you could only use it in partials and it had to be the last statement.

So you can either upgrade to the latet Hugo ore rewrite the partial to:

```auto
{{ $res := ""
{{ with resources.GetRemote site.Params.endpoint }}
    {{ $res = transform.Unmarshal . }}
{{ end }}
{{ return $res }}

```

In any case I would make sure to always `return` something (e.g. a blank string when not found).

---

<div class="post-metadata">

**Author:** ![abrusle](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@abrusle](https://discourse.gohugo.io/u/abrusle)\
**Post date:** [September 24, 2026, 5:44pm UTC](https://discourse.gohugo.io/t/unmarshal-fails-when-called-from-a-partial-template-in-a-content-adapter/57583/7 "2026-09-24T17:44:46Z")

</div>

Okay, that makes sense.

I rewrote the partial like you suggested and it works!  
I’ll apply that to my (larger) project tomorrow morning and post a final update here.

Thank you very much for your help! 😃

---

<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 24, 2026, 6:15pm UTC](https://discourse.gohugo.io/t/unmarshal-fails-when-called-from-a-partial-template-in-a-content-adapter/57583/8 "2026-09-24T18:15:46Z")

</div>

with error handling for GetRemote you might also need to modernize to the new error handling introduced with 141

> **[resources.GetRemote](https://gohugo.io/functions/resources/getremote/)**
>
> Returns a remote resource from the given URL, or nil if none found.

---

<div class="post-metadata">

**Author:** ![abrusle](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@abrusle](https://discourse.gohugo.io/u/abrusle)\
**Post date:** [September 25, 2026, 8:26am UTC](https://discourse.gohugo.io/t/unmarshal-fails-when-called-from-a-partial-template-in-a-content-adapter/57583/9 "2026-09-25T08:26:58Z")

</div>

Quick update: the fix does work in my main project ✅

> with error handling for GetRemote you might also need to modernize to the new error handling introduced with 141

@irkode Thank for the advice, I am in fact using the new error handling feature in my project. I simply removed it for the minimal reproduction code when trying to debug the issue 🙂

---

<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 27, 2026, 8:27am UTC](https://discourse.gohugo.io/t/unmarshal-fails-when-called-from-a-partial-template-in-a-content-adapter/57583/10 "2026-09-27T08:27:02Z")

</div>

Closed on September 27, 2026, 8:27am UTC

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