Error calling partial: partial "partial/defaultFigure" not found

Can you spot in this below, what causes the partial not be found, despite the names being unique and only present in that file ?

render-image.html
{{ if (or .Attributes.cite $.Title) }}
	{{ partial "partial/defaultFigure" . }}
{{ else }}
	{{ partial "partial/defaultImage" . }}
{{ end }}

{{ define "partial/defaultFigure" }}
	<figure {{with .Attributes.id}}id={{.}}{{end}} class="{{with .Attributes.class}} {{.}}{{end}}">
	{{ with .Title }}<figcaption>{{.|$.Page.RenderString}}</figcaption>{{ end }}
	{{ partial "partial/defaultImage" .}}
	{{with .Attributes.cite}}<cite>— {{.|$.Page.RenderString}}</cite>{{end}}
	</figure>
{{ end }}

{{ define "partial/defaultImage" }}
	{{- $img := "" -}}
	{{- $destination := urls.Parse .Destination }}
	{{- if $destination.IsAbs }}
		{{- $img = resources.GetRemote $destination.String }}
	{{- else }}
		{{- with .Page.Resources.Get $destination.Path }}
			{{- $img = . }}
		{{- else }}
			{{- $img = resources.Get $destination.Path }}
		{{- end }}
	{{- end }}
	{{ $Type := "video"}}
	{{ if eq $img.MediaType.MainType "image" }}
		{{ if in $img.MediaType.Suffixes "svg" }}
			{{ $Type = "svg" }}
		{{ else }}
			{{ $Type = "image"}}
		{{end}}
	{{end }}
	{{ if eq $Type "svg" }}
		{{$img.Content}}
	{{ else if eq $Type "video" }}
	<video autoplay loop muted controls poster><source width=2OO src="{{ $img.RelPermalink }}" type="video/{{path.Ext $destination.Path}}">There should have been a video here but your browser does not seem to support it.</video>
	{{ else }}
	<a role=presentation target="_blank" {{with .Attributes.link}}href="{{.}}" rel="nofollow external"{{else}}href="{{$img.RelPermalink}}"{{end}}>
	{{ $src := slice }}
	{{- $smallest := "" -}}
	{{- $very_small := "" -}}
	{{- $small := "" -}}
	{{- $medium := "" -}}
	{{ if gt $img.Width 200 }}
		{{ $smallest = $img.Resize "200x q95" }}
	{{ else }}
		{{ $smallest = $img }}
	{{ end }}
	{{ if gt $img.Width 400 }}
		{{ $very_small = $img.Resize "400x q95" }}
	{{ else }}
		{{ $very_small = $img }}
	{{ end }}
	{{ if gt $img.Width 604 }}
		{{ $small = $img.Resize "604x q95" }}
	{{ else }}
		{{ $small = $img }}
	{{ end}}
	{{ if gt $img.Width 800 }}
		{{ $medium = $img.Resize "800x q95" }}
	{{ else }}
		{{ $medium = $img }}
	{{ end}}
	{{ range uniq (slice $medium $small $very_small $smallest) }}
	  {{ $src = $src | append (printf "%s %dw" .RelPermalink .Width) }}
	{{ end }}
	<img src="{{$medium.RelPermalink -}}" srcset="{{ delimit $src `, ` }}" loading="{{with .Attributes.loading}}{{ . }}{{else}}lazy{{end}}" {{with .Attributes.loading}}fetchpriority=high{{end}} {{with default .Title .Text }}alt="{{.}}"{{end}} {{ with .Title }}title="{{ .|plainify }}"{{end }} sizes="(max-width: 350px) 100vw, (max-width: 600px) {{if in .Attributes.class "center"}}100vw, 70vw{{else}}50vw, 400px{{end}}" {{with $medium}}width="{{.Width}}px" height="{{.Height}}px" style="--height-limit:{{.Height}}px; background: linear-gradient({{- delimit ($img.Colors) ", " -}})"{{end}}>
	</a>
	{{end}}
	{{ if not .IsBlock}}{{ errorf "%q %q: Here images wrongly stacked on the same line" .Page.Path .Destination }}{{end}}
{{ end }}

For inline/nested templates, use template instead of partial.

{{ if (or .Attributes.cite $.Title) }}
	{{ template "partial/defaultFigure" . }}
{{ else }}
	{{ template "partial/defaultImage" . }}
{{ end }}

See template package - text/template - Go Packages.

Thanks, I never consult anything else but the hugo website. But why did it work before ? And why does my other render-image.html (a simpler one, granted) works with “partial” ?

You can do that, but there’s no need to…

layouts/_default/home.html

{{ partial "foo.html" . }}

layouts/partials/foo.html

{{ partial "bar.html" . }}

{{ define "partials/bar.html" }}
  {{ return "baz" }}
{{ end }}

Notes:

  1. Always include the .html suffix when calling or defining the partial
  2. Partials defined inline, as shown above, are globally available. That means there can be name collisions with templates in the partials directory, and with other inline partials. So, you might want to do something like this instead:

layouts/partials/foo.html

{{ partial "inline/foo/bar.html". }}

{{ define "partials/inline/foo/bar.html" }}
  {{ return "baz" }}
{{ end }}
1 Like

I’m puzzled as to why “partials/bar.html” calls on “bar.html”, puzzled as to why “.html” should be necessary when inline and so said html file doesn’t exist, and as to why “template” and “partial” are here two interchangeable keywords. And finally then puzzled as to why doing something you say is unnecessary, actually unlocked my situation… Am I right that this behavior is quite unpredictable ?

Perhaps it seems so to you.