Mind you, if I take out the $feature bits, everything works. So I don’t understand why I can pull the images inside the post from the leaf bundle, using the same logic (!!), but can’t pull the “featured image”.
Error
Rebuild failed:
Failed to render pages: render of "page" failed: "D:\Sites\rsdc\layouts\_default\about.html:4:144": execute of template failed: template: _default/about.html:4:4: executing "main" at <partial "blog/post-header.html" .>: error calling partial: "D:\Sites\rsdc\layouts\partials\blog\post-header.html:4:144": execute of template failed: template: partials/blog/post-header.html:4:144: executing "partials/blog/post-header.html" at <$feature.Resize>: nil pointer evaluating resource.Resource.Resize
2
3
4
5
6
{{ $me := (resources.Get "images/me.jpg").Resize "450x webp 85q" }}
{{ partial "blog/post-header.html" . }}
<section class="about-me">
hugo v0.91.2-1798BD3F+extended windows/amd64 BuildDate=2021-12-23T15:33:34Z VendorInfo=gohugoio
Reload Page
You need to understand where you are at with your dot . - context. With a render hook you are “inside” of the current parsed layout with its content right available to the renderhook. What I am trying to say is that .Page in a render hook will always point to the currently parsed page the renderhook is in.
Your template or layout file however is somewhere in a context (where you load it) and it could be that there is no .Page available or the dot is the page itself. That depends on your layouting.
Untested, but if I remember it right you could just do $.Page, but I don’t know if that would change things in the render hook. As those are typically two separate files keep the .Page there and in the error-layout-file try working with $.Page.
From the limited templates you posted I would say in your layout (not in the renderhook) it should be something like this:
PS: I just saw you linked your repo. The code above should work. Remove the .Page from the partial. Look inside of your template, you are already inside of the “page context” (or the .Content would not work some lines later).
After fixing Problem 1, the build still throws an error:
failed to render pages: render of “page” failed: “/home/jmooring/temp/rsdc/layouts/_default/about.html:4:144”: execute of template failed: template: _default/about.html:4:4: executing “main” at <partial “blog/post-header.html” .>: error calling partial: “/home/jmooring/temp/rsdc/layouts/partials/blog/post-header.html:4:144”: execute of template failed: template: partials/blog/post-header.html:4:144: executing “partials/blog/post-header.html” at <$feature.Resize>: nil pointer evaluating resource.Resource.Resize
This occurs because content/about.md:
Is not a page bundle, and consequently
Has no resources, and consequently
Does not a have a feature image
You need to code defensively, keeping in mind that one or more content pages rendered by a given template may not have a particular resource. For example:
{{ with $feature := .Page.Resources.GetMatch "feature.*" }}
...
{{ end }}
Problem 3
After fixing Problem 1, the build throws this warning:
WARNING: calling IsSet with unsupported type “invalid” () will always return false.
the third problem is not something I can fix, as it isn’t something I can control. I can only let the Welcomments folks know what is going on.
I’ll make a new topic, if you want, but your fix has created an interesting problem: Everything is now scoped to the featured image.
This results in no post data being displayed, only image data.
EDIT: Never mind, I fixed this quickly. I realized I was scoping the entire partial to the {{ with [...] }}, so now my code works, and looks like this: