Case sensitivity: index function supports only all-lower-case key values

I encountered a case-sensitivity issue with the index template function using Hugo v0.29: I define site parameter and key names in the config file using camel-case capitalization — e.g., a paramName parameter with a paramKey key. I can use the following syntax in templates and shortcodes to directly access the parameter key using the original camel-case capitalization:
{{ $.Site.Params.paramName.paramKey") }}
But if I use the camel-case key capitalization in a call to the index function in my shortcode, the function fails to locate the key:
{{ (index $.Site.Params.paramName "paramKey") }}
Passing an all-lower-case version of the key name to index works:
{{ index $.Site.Params.paramName "paramkey" }}
This can also be done by using the lower function:
{{ index $.Site.Params.paramName (lower "paramKey") }}
(In v0.25 of Hugo, the direct access also seems to support only all-lower-case key parameters.)
–> Is this a known issue, and are there any plans to change this behavior?

I would prefer to use camel-case capitalization in parameter-key names. However, it’s more important to me to use the same capitalization consistently throughout the code, and I also want to avoid extra function calls (using lower), so for now, I opted to use all lower-case parameter key names with underscores.

Since Hugo v0.18, “All the Params configurations are now case insensitive” according to the changelog.

I think it would make more sense if functions that work with params (like index from your post) are also case insensitive then.

Otherwise we’d have to access params in two ways (case insensitive in the theme template files and case sensitive with index et al) so that probably adds to confusion. And also extra work (look up the correct casing for params).

So I agree with @sharonl and would favour case insensitivity for a higher fault tolerance and allowing people to use their own preferred casing (like camel case).

1 Like