From ab574da6ab952d9cf69e59be04e36e5258706b49 Mon Sep 17 00:00:00 2001 From: Matthew Sanabria Date: Sat, 21 Jun 2025 22:11:05 -0400 Subject: [PATCH] layouts: correctly check for template existence https://github.com/jpanther/congo/commit/4e4b470915171a5855f3f2ea25851995aace8b55 fixed the theme for building with Hugo v0.146.0 or later but it doesn't correctly check for template existence. That is, if you set `homepage.layout` to `profile` this theme will still load the `page` layout. Hugo's [templates.Exists](https://gohugo.io/functions/templates/exists/) function tests for the existence of templates relative to the `layouts` directory. The example code they provide uses `printf` to join the template name with the `_partials` directory, which would be `partials` instead for this theme. ``` {{ $partialPath := printf "headers/%s.html" .Type }} {{ if templates.Exists ( printf "_partials/%s" $partialPath ) }} {{ partial $partialPath . }} {{ else }} {{ partial "headers/default.html" . }} {{ end }} ``` --- exampleSite/layouts/partials/home/custom.html | 4 ++-- layouts/_default/baseof.html | 2 +- layouts/index.html | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/exampleSite/layouts/partials/home/custom.html b/exampleSite/layouts/partials/home/custom.html index a145efc..07b7db7 100644 --- a/exampleSite/layouts/partials/home/custom.html +++ b/exampleSite/layouts/partials/home/custom.html @@ -1,9 +1,9 @@ {{ $jsHome := resources.Get "js/home.js" | resources.Minify | resources.Fingerprint "sha512" }}
- {{ partial "partials/home/page.html" . }} + {{ partial "home/page.html" . }}