mirror of
https://github.com/TrezOne/congo-hindi-gujarati.git
synced 2026-06-15 04:52:55 -04:00
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 }} ```
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
>
|
||||
</div>
|
||||
{{ $header := print "header/" .Site.Params.header.layout ".html" }}
|
||||
{{ if templates.Exists $header }}
|
||||
{{ if templates.Exists ( printf "partials/%s" $header) }}
|
||||
{{ partial $header . }}
|
||||
{{ else }}
|
||||
{{ partial "header/basic.html" . }}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{{ define "main" }}
|
||||
{{ $partial := print "home/" .Site.Params.homepage.layout ".html" }}
|
||||
{{ if templates.Exists $partial }}
|
||||
{{ if templates.Exists ( printf "partials/%s" $partial) }}
|
||||
{{ partial $partial . }}
|
||||
{{ else }}
|
||||
{{ partial "home/page.html" . }}
|
||||
|
||||
Reference in New Issue
Block a user