Dynamic partial paths

I try to include partial to a single page template via dynamic path. I do the following:

{{ $a := "partials/synopsis/" }}
{{ $b := .Params.id }}
{{ $c := ".html" }}

{{ $address := printf "%s" $c | printf "%s%s" $b | printf "%s%s" $a | printf "%s" }}
{{ print $address }}

That prints the correct path “partials/synopsis/0548.html” on my page.

But when i add this:

{{ partial $address . }}

Hugo shows an error.

render of "page" failed: "/Users/ivanzolotov/Desktop/playground/layouts/_default/single.html:20:9": execute of template failed at <partial ($address) .>: error calling partial: partial "partials/synopsis/.html" not found render of "page" failed: partial "partials/synopsis/.html" not found  failed to render pages: partial "partials/synopsis/.html" not found

I cant understand why $address variable is ’loosing’ .Params.id part of my path. Can you please help me?

I suspect that one of the pages rendered by this template does not have the ID set in front matter.

1 Like

Yes it is! Thank you! I have two different page categories: pages in one have ids in front matter, pages in another don’t have ones. The second category was created for testing only. I’ve removed it, now every page has ‘id’ and everything works.

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