I’ve read every half-relevant previous forum question (and some Stack Overflow answers) about this issue, and have yet to find an answer that works for me; so I will throw myself on your collective mercies here.
The scenario: I am trying to thin down my overall SCSS/CSS by applying certain styling only on pages with one or more applicable tags — hence, I test for the presence in .Params.tags
of the tag(s). Here’s a relevant section from the head.html
partial (a repo branch link is at the bottom of this submission):
{{- $cssBuild = slice (resources.Get "scss/critical.scss") -}}
{{- if in .Params.tags "contact" -}}
{{- $cssBuild = $cssBuild | append (resources.Get "scss/_billboard.scss") -}}
{{- end -}}
{{- $css := $cssBuild | resources.Concat "scss/css.scss" | resources.ToCSS $optionsCSSFileComp | fingerprint "md5" -}}
The problem: the if in .Params.tags "contact"
line doesn’t return as true even if there’s a tags: contact
entry on the page, so the append
doesn’t happen, thus leaving the desired tag-specific SCSS out of the final result. Yet, weirdly, in a test instance further down on the page (in a content:
item in a noscript
-related style
), the presence of “contact” in .Params.tags
does test as true, as it should.
Also, if I take the append
out of the conditional, the append works fine, although that’s not what I want since I’m trying to pare down to only that SCSS which a page needs according to how I’ve tagged its front matter.
I based this in part on Issue when trying to only load page-specific SCSS stylesheets, and it apparently worked for him (albeit with some other, unrelated problems he reported). So there’s probably something I’m stupidly overlooking but, after staring at it off-and-on for the last 18 hours or so, I concede defeat. I’ve put this in a branch of my site repo at GitHub - brycewray/hugo_site at if-tags. Thanks in advance for any help someone may be able to offer!