Help with .Resources.ByType "image"

This is embarrassing.

I’m trying to call an image with .Resources.ByType from within a shortcode.

Here is my structure:

And here is the shortcode

character.html

{{ with .Resources.ByType "image" }}
       {{ range . }}
       {{ .RelPermalink }}
       {{ end }}
{{ end }}

the error

executing "shortcodes/infobox/character.html" 
at <.Resources.Match>: can't evaluate field Resources in type *hugolib.ShortcodeWithPage

Any help will be highly appreciated.

.Page.Resources.ByType

Sadly, something’s wrong with it.

{{ with .Page.Resources.ByType "image" }}
        {{ range . }}
             {{ .RelPermalink }}
        {{ end }}
{{ end }}

Outputs nothing.

If I do this:

{{ $ca := .Page.Resources.ByType "image" }}
{{ $ca.RelPermalink }}

It outputs this:

``

 execute of template failed: template: shortcodes/infobox/character.html:13:14: executing "shortcodes/infobox/character.html" at <$ca.RelPermalink>: can't evaluate field RelPermalink i

``

If I do this:

{{ .Page.Resources.ByType "image" }}

I get this: []

It’s not wrong and since you gave no more details I can only assume you’re trying to use that in the my-first-entry.md, when that’s not how page resources work. AFAIK that should be a index.md, in a folder along the image files.

1 Like

Thanks Pal. Also, Thanks @bep.
I’m working on a MediaWiki-like setup for those who wish to use Hugo to document their projects. Bootstrap 5 + Hugo, nothing else.

Here’s my progress:

And because I can… night mode.

With errors, because why not…

You have a solution??

{{ range (.Resources.ByType "image") }}

works for me

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