templates.Exists does not work with layout files in module mounts. Is there a way to somehow either check if the template exists or warn a bit more verbose? Currently {{ partial "somefile" . }} with a non-existing path just silently continues. Which might be nice, but does not help debugging issues.
On a sidenote: having templates.Exists work within themes and modules would be very nice. A go-dummy like me would even expect it to work out of the box. I would expect Hugo to have some kind of layout tree after resolving all modules. I remember having asked that or even opened an issue about it with an answer that I remember only as “won’t work”.
{{- /* open search meta data */ -}}{{- $partialOpensearch := "head/opensearch" -}}
{{- if templates.Exists ( printf "partials/%s" $partialOpensearch ) -}}
{{- partialCached "head/opensearch" . -}}
{{ else }}
{{ warnf "bla" }}"}}
{{- end -}}
With a module that has the file layouts/head/opensearch.html existing this results in “bla” in the logs. Calling the partial directly (removing all but the partial line) leads to the inclusion of the partial. Removing the module leads to Hugo ignoring the missing partial.
So. “Sure” in sense of a boolean true in regards to Go language - nope. I wouldn’t be surprised if I apply something wrong. But sure as in that happens in my templates and it did happen so in earlier cases. I also remember bringing it up some time ago and your answer was something about module mounts and go limitations. I can’t find that, so I hope it’s not an artificial memory
You need to include any suffix in the template lookup (e.g. “partials/cool.html” not just “partials/cool”). The partial func has a fallback, which makes it work without any suffix.