Can't fetch parameter set in front matter from partial template

Hello everyone,
In this theme I’m working on

I have all my uploaded pictures in the assets directory as follows:

└── uploads
    ├── 2009
    │   └── 10
    │       └── silver-slack.png
    ├── 2010
    │   ├── 10
    │   │   └── screenshot-5.jpg
    │   └── 11
    │       └── nimoy-spock.jpg
    ├── 2011
    │   ├── 07
    │   │   ├── Boy-on-Mount-Fuji-large.jpg
    │   │   ├── Choshi-in-Shimosa-Province-Soshu-Choshi-large.jpg
    │   │   ├── Hibiscus-and-Sparrow-large.jpg


If I call them inside my content from a shortcode there’s no problem, but what I’m failing to achieve is to use one of those pictures as header background image called from a partial.

If you look at the theme, I call the partial head.html which calls the partial head-addition.html

Inside the head-addition.html file I try to set an image as header background if it is declared in the front matter of the page I’m rendering, but hugo complains:

execute of template failed: template: partials/head-addition.html:10:36: executing "partials/head-addition.html" at <$image.Permalink>: nil pointer evaluating resource.Resource.Permalink

And I can’t figure out why.

In the Front Matter of the article I specify:

title: "blabla"
featured_image: "uploads/2020/11/nimoy-spock.jpg"

Can you guys help me pinpoint the mistake I’m obviously overlooking?
Thanks a lot in advance

I think there is a typo of featured_image’s year 2020, the image was saved as 2010.

Btw, the code could be improved as below:

{{ with $.Params.featured_image }}
  {{ with resources.Get . }}
    <style media="screen">
      #banner {
        background-image: url( {{ .Permalink }} );
  {{ else }}
    {{ warnf "featured image not found: %s" . }}
  {{ end }}
{{ end }}

thanks for your reply,
the typo was only here, in the actual article it was written correctly, sorry but I didn’t check when writing the post here.

Anyway, I checked your code and it works, so I’ll mark it as solved.
Thanks a lot

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