Since updating from v.138 to v0.147.3+extended+withdeploy, one of my pages, which uses remote data, won’t build properly.
The setup which had been working:
a page at content/bdr.md had a frontmatter layout which specified api
there was a layouts/_default/api.html file, which contained code fetching remote json:
{{ $url := "https://repository.library.brown.edu/api/collections/bdr:88np2gke" }}
{{ with try (resources.GetRemote $url) }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else with .Value }}
{{ $data = . | transform.Unmarshal }}
<ul>
{{ range $artifacts := $data.items.docs }}
<li>
<a href='{{ $artifacts.uri }}'>
{{ $artifacts.primary_title }}
</a>
</li>
{{ end }}
</ul>
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource %q " $url }}
{{ end }}
Seeing the breaking changes in 146, I moved my api.html file to layouts, and was still getting the error execute of template failed: template: api.html:15:28: executing "api.html" at <$data.items.docs>: can't evaluate field docs in type interface {} when I tried to build the site.
I tried to make the api.html file into a content/bdr/api.gotmpl file, and while that got rid of the build error and built the page itself, the loop didn’t produce any content, and I don’t think that’s the right approach, since I’m not trying to create multiple Hugo pages, just render what’s in the remote json. I’ve tried putting <pre>{{ debug.Dump $data }}</pre> in right after the transform.Unmarshal function, but I don’t get any debugging info. There’s no error or warning in the console or terminal. I’ve searched the forum and read all the topics on the recent template restructuring.
I tested with your code and it works great. Try it:
git clone --single-branch -b hugo-forum-topic-54736 https://github.com/jmooring/hugo-testing hugo-forum-topic-54736
cd hugo-forum-topic-54736
hugo server
Okay, I feel insane. Our code is identical, it is clearly something I haven’t thought of. I’ve made the repo public if you want to take a look at branch hugo-146.
I didn’t think the template changes were what caused the problem, but it was the only thing I changed after reading the release notes for 146, and I didn’t see any other breaking changes that were relevant. I haven’t been able to get debug.Dump to produce output for $data and I’ve reviewed the json that I’m fetching, so I’m pretty sure that the structure s right.
That seems to have done the trick! Thanks, I never would have figured that out on my own. (I did have to do some hunting in the docs to find out where the cache directory is for me, but that was straightforward enough.)