Get: dirs not supported resource types when trying to use param value

I’m trying to add a featured image to my templates but I run into the following error.

Failed to render pages: render of "home" failed: "/[...]/layouts/index.html:7:24": execute of template failed: template: index.html:7:24: executing "main" at <resources.Get>: error calling Get: dirs not supported resource types: &{0xc0010b3330 map[baseDir:/[...] filename:assets isOrdered:false lang: module:project mountRoot: mountWeight:2 opener:0x4833e70 watch:true]}

My posts have following config

title: “Title?”
date: 2020-07-05T09:42:49+02:00
draft: false
tags: [“Tag”,“Tag2”]
- “img/image.jpg”
featured_image: “/images/image.jpg”

The images is in assets/images.
I have tried numerous ways
Attempt 1
{{ $src := .Params.featured_image }}
{{ $res := resources.Get ($src) }}

Attempt 2
{{ src := .Param “featured_image” }}
{{ $res := resources.Get ($src) }}

Attempt 3
{{ $src := .Params.featured_image }}
{{ $res := resources.Get ( .Params.featured_image) }}

Attempt 4 Returns nil error
{{ $src := resources.GetMatch (printf “**%s” .Params.featured_image) }}

And a bunch more. Only method that works is actually hardcoding the image path.

Only way that works
{{ $res := resources.Get "images/image.jpg }}

How can I get this sorted?

I don’t want to use page bundles since I just want to write blog posts as and put them in my posts folder. Not use page bundles since they are convoluted. Not that I can get param based images to work with page bundles either. Same issues.

One or more of the pages over which you are ranging does not have a featured_image. You need to test for existence:

{{- with .Params.featured_image -}}
  {{ $res := resources.Get . }}
{{- end -}}

Of course. That totally slipped my mind.

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