Config and Frontmatter params case-inconsistency

Hi everybody,

I just wanted to use some parameter in the config of my project
and wanted to use the isset function.

I thought I’ve sticked to the Hugo naming scheme in the config by using camel-case for my
parameters. But it turns out, that all parameters are transformed to lowercase internally.

The dot-notation is not effected by this, as it appears to transform all parameters to lowercase anyways.
However functions like isset and index are not doing so. Resulting in failing calls like:

{{ isset $.Site.Params myValue }}

Even though it was defined that way, while you may access:

{{ $.Site.Params.myValue }}

In my opinion the behaviour should be consistently case-insensitive or case-sensitive.

To showcase the problem, I created a small example project here:

Which can be accessed online here:
https://ukmasmu.gitlab.io/hugo-bug-all-params-lowecase/

Hugo Version: 0.55.6
Hugo Static Site Generator v0.55.6-A5D4C82D windows/amd64 BuildDate: 2019-05-18T07:57:00Z

I haven’t found much informations about this behaviour.
In my opinion it’s a bug, but maybe it’s intended behaviour.
If it’s considered a bug I’ll open an issue. Just wanted to ask your guys opinion beforehand,
maybe I’m missing something here.

Best regards,
Sev

or more widely,

https://discourse.gohugo.io/search?q=params%20lowercase

Thanks for your reply,

but the main problem is not that the param is stored in lowercase or can be accessed caseinsensitive (here you get the expected result with the camel-cased access.)

But that the functions like isset (or index) fail when using the exact declaration as in the config.
This is inconvenient and a big pitfall. I’m not so familiar with hugos architecture yet, but if the functions are declared within the hugo framework, then I would adjust them to work with the parameters I declare and not to have the knowledge about the lowercase map behind the scenes. Or introduce appropriate parameter specific ones.

Thanks to your search link I stumbled upon this old post, that has the same issue, with people falling down the same pitfall
https://discourse.gohugo.io/t/config-params-should-be-all-lowercase-or-not/5051

Understanding correctly, the isset behaviour was seen as unintended back then, but wasn’t fixed since.

However I overlooked that the behaviour is in fact documented.
I just visited the isset page, where it’s explicitly mentioned:

All site-level configuration keys are stored as lower case. Therefore, a myParam key-value set in your site configuration file needs to be accessed with {{if isset .Site.Params "myparam"}} and not with {{if isset .Site.Params "myParam"}} . Note that you can still access the same config key with .Site.Params.myParam or .Site.Params.myparam , for example, when using with .

But IMO this behaviour is bad practice nontheless. Also taking in consideration, that camelCase is used in all config files I stumbled upon (e.g. https://gohugo.io/getting-started/configuration/#example-configuration).

1 Like