This is a weird one. One of those where some code which has been working perfectly in one site, refuses to work in another.
I’ve just duplicated a theme from one Hugo site to use as a starting point for another. There is some conditional template code to show tags [if they exist] as keywords in the header and as a clickable list at the bottom of each post. Heres what I have:
In frontmatter of post:
tags = ["oil", "pressure sensor", "leak", "switch"]
In /themes/mytheme/layouts/partials/header.html:
<meta name="keywords" content="{{ if isset .Params "tags" }}{{ range .Params.tags }}{{ . }}, {{ end }}{{end}}">
Works perfectly. Rendered HTML includes the tags:
<meta name="keywords" content="oil, pressure sensor, leak, switch, ">
Then, in /themes/mytheme/layouts/_default/single.html I have the following:
{{if isset .Params "tags" }}
<span class="footermetaheading">Meta</span>
TAGS: {{ range .Params.tags }}<a class="tag" href="/tags/{{lower . }}">{{lower . }}</a>, {{ end }}<br/>
ORIGINAL PUBLICATION DATE: {{.Date.Format "02 Jan 2006"}}<br/>
AUTHOR: {{ .Site.Params.mdrauthor }}
{{ end }}
{{"<!-- end if it's a blog page show META //-->" | safeHTML}}
{{ end }}```
And nothing at all gets output. As I say, it's made all the more mysterious because the code is directly lifted from another of my site's themes, where it works perfectly.
Anything I might have missed here?
PS: In other [possibly] related news; in the aforementioned other site, some other conditional code has suddenly stopped working as well:
I have set a ```mdrposticon``` variable in the frontmatter for my posts, where I select from a folder full of icon images for that post. If I don't specify a post icon, the template is supposed to fall back on the default icon. Here is the code:
Frontmatter: ```mdrposticon = ""``` [can be set or left blank]
And then in */themes/mytheme/layouts/_default/list.html* and */themes/mytheme/layouts/index.html* I have the following:
```<div class="posticon">
{{ if isset .Params "mdrposticon" }}
<img src="{{.Params.mdrposticon }}" />
{{"<!-- Posticon. Otherwise show default //-->" | safeHTML}}
{{ else }}
<img src="/icons/default.png" />
{{ end }}
</div>```
Which was working last time I built the site. But now will not output anything, if I've not defined ````mdrposticon```` in the frontmatter.
I've not updated Hugo since last I built the site, so this is a complete mystery. But it seems strangely coincidental that two pieces of code relying on ``{{ isset }`` have started acting up. Can anyone think of anything else, however seemingly unrelated, that might be borking this?
Hugo doesn't throw up any errors, on building the sites.