Error with layouts/type/_markup/render-{kind}.html

Hi.
I made a different render-image for the homepage (with type:home) and it’s seen as such, but I have this error message:

“/home/drm/WEBSITE/themes/hugo-book/layouts/home/_markup/render-image.html:24:13”: execute of template failed: template: home/_markup/render-image.html:24:13: executing “home/_markup/render-image.html” at <$img.Width>: error calling Width: this method is only available for image resources

  {{ $quality = .Page.Param "imaging.quality" }}
{{ end }}
{{ if gt $img.Width 1540 }}
	{{ $large = $img.Resize (print "1540x q" $quality) }}
{{ else }}

What’s wrong here ?

Complete file

{{- $img := “” -}}
{{- $smallest := “” -}}
{{- $small := “” -}}
{{- $medium := “” -}}
{{- $large := “” -}}

{{- /* Get image resource. */}}
{{- $destination := urls.Parse .Destination }}
{{- $img := “” }}
{{- if $destination.IsAbs }}
{{- $img = resources.GetRemote $destination.String }}
{{- else }}
{{- with .Page.Resources.Get (urls.Parse .Destination).Path }}
{{- $img = . }}
{{- else }}
{{- $img = resources.Get $destination.Path }}
{{- end }}
{{- end }}

{{ $quality := 100 }}
{{ if gt (len $img.Content) 100000 }}
{{ $quality = .Page.Param “imaging.quality” }}
{{ end }}
{{ if gt $img.Width 1540 }}
{{ $large = $img.Resize (print “1540x q” $quality) }}
{{ else }}
{{ $large = $img.Resize (printf “%dx%d q%d” $img.Width $img.Height $quality) }}
{{ end}}
{{ if gt $img.Width 1000 }}
{{ $medium = $img.Resize (printf “1000x q%d” $quality) }}
{{ else }}
{{ $medium = $img.Resize (printf “%dx%d q%d” $img.Width $img.Height $quality) }}
{{ end}}
{{ if gt $img.Width 604 }}
{{ $small = $img.Resize (printf “604x q%d” $quality) }}
{{ else }}
{{ $small = $img.Resize (printf “%dx%d q%d” $img.Width $img.Height $quality) }}
{{ end}}
{{ if gt $img.Width 200 }}
{{ $smallest = $img.Resize (printf “200x q%d” $quality) }}
{{ else }}
{{ $smallest = $img.Resize (printf “%dx%d q%d” $img.Width $img.Height $quality) }}
{{ end }}

{{ with .Title }}{{.|$.Page.RenderString}}{{ end }}

I don’t think I changed anything important, especially in the beginning. Just removed the useless parts.

Are you sure there’s no … error message?

If I would guess, you have some pages without imaging.quality set. try:

 {{ $quality = .Page.Param "imaging.quality" | default 50 }}

My bad, I badly copied the error message.

OK, you have somehow found a resource that’s something other than a raster image (e.g. a text file).

You can check the media type with e.g. $img.MediaType.MainType which should be image.

no it has to be a syntax mistake, because everything worked before. Even without default.
Is this the good syntax for what it’s obviously supposed to mean ?

  {{ $quality = (default .Site.imaging.quality .Page.Params.imaging.quality) }}

with this in my config:

[imaging]
  anchor = 'Smart'
  bgColor = '#ffffff'
  hint = 'picture'
  quality = 75

Error:

Error: Error building site: “/home/drm/WEBSITE/content/docs/Biology/virus-exosome-en.md:1:1”: “/home/drm/WEBSITE/themes/hugo-book/layouts/_default/_markup/render-image.html:25:32”: execute of template failed: template: _default/_markup/render-image.html:25:32: executing “_default/_markup/render-image.html” at <.Site.imaging.quality>: can’t evaluate field Site in type goldmark.imageLinkContext

Use site.Image.quality. I think the context is not the page context, but e.g. with or range. Using site avoids using the (.) which changes.

You must mean site.imaging.quality I suppose. still complaining.

execute of template failed: template: _default/_markup/render-image.html:25:26: executing “_default/_markup/render-image.html” at : can’t evaluate field Image in type interface {}
Built in 537 ms

line 25 is:

{{ $quality = default site.imaging.quality .Page.Params.imaging.quality }}

Do you have any SVGs? They can’t have quality changed but detect as images.

None going through the render-hook.
Here’s a sample:
https://drive.google.com/drive/folders/1wG_qK0jXQfpaIVodJKUWVTKfTK3xg6US?usp=share_link

found the solution.
i replaced type: home but layout: home. Pfff, if that is not confusing I don’t know what it is. And it ain’t gonna change…
I would still suggest though, explaining on the site the difference in behavior. this sðit is confusing as hell. Using type did apply to the homepage, but to apparently all the other pages too since the error message concerned a completely unrelated page.