Conditional pipe for SCSS processing in Hugo template

The below code works great for processing SCSS into CSS, and then minifying and fingerprinting.

{{ $style := resources.Get "scss/style.scss" | resources.ToCSS $options | resources.Minify | resources.Fingerprint }}

I would like to be able to set whether or not to fingerprint CSS files in the site config file, like so:

      fingerprint: true

In my template, I have tried the following:

{{ $style := resources.Get "scss/style.scss" | resources.ToCSS $options | resources.Minify ( if eq .Site.Params.fingerprint true ) | resources.Fingerprint ( end ) }}

which throws the error unexpected <if> in parenthesized pipeline.

Is it possible to include a pipe, only if a param is set?

Something like:

{{ with .Site.params.fingerprint }}
  {{ $style := resources.Get "scss/style.scss" | resources.ToCSS $options | resources.Minify | resources.Fingerprint }}`
{{ else }}
  {{ $style := resources.Get "scss/style.scss" | resources.ToCSS $options | resources.Minify  }}
{{ endif }}
1 Like

Thank you. While that is an option, I would like to make multiple pipes configurable- including PostCSS and minify, and I’d like to avoid a separate else statement for every combination of the three. I’m not finding anything on how to achieve that, so not sure it’s possible at all.

Am curious, why?

In fairness, having a separate else statement for each combination would only be 6 in total, to account for any combination of minifying, postCSS and fingerprinting. I am probably over complicating the issue. For now, I will just use the method suggested by nfriedli.