I have an issue setting environment variables on compile if the parameter name has an underscore in it.
I’m trying to set the variable called api_key under a section called map in a config file called params.toml. I have verified that I can set another parameter called zoom under the same section with the following command:
env HUGO_PARAMS_MAP_zoom="15" hugo
But trying the same with api_key fails. I’m guessing it’s to do with the underscore in the parameter name. I’ve tried to wrap api_key in brackets, single and double quotation marks and I’ve tried to escape the underscore api\_key. Nothing works. Anyone knows how to do this?
Your method does indeed inject the correct parameters into the configuration. If I look at the config after injection using the following command
HUGO_PARAMS_MAP='{"engine":"1","api_key":"12345","zoom":"15"}' hugo config | grep -I params
I do get map[engine:1 api_key:12345 zoom:15], but for some reason the map breaks if I compile using hugo server or hugo. The map is completely gone, frame and all. The space for the map is still allocated in the html, but it’s just blank.
git clone --single-branch -b hugo-forum-topic-28715 https://github.com/jmooring/hugo-testing hugo-forum-topic-28715
cd hugo-forum-topic-28715
HUGO_PARAMS_MAP='{"engine":"1","api_key":"12345","zoom":"15"}' hugo server
At a minimum, you must define an empty params.map in config.toml.
So that part works:) Now, these three parameters define a embedded google map, which doesn’t show up when I inject the parameters. It must be a problem with the theme I use (Wowchemy) I guess. But it’s just strange that this parameter injection into the configuration changes something outside the config file!
These three parameters already exist in the configuration, so it’s not like I’m creating new parameters.
./config/_default/params.toml
[map]
# To show your address on a map in the Contact widget, enter your latitude and longitude (above)
# and choose a map provider below.
#
# To use Google Maps, set `engine` to 1 and enter your API key that can be obtained here:
# https://developers.google.com/maps/documentation/javascript/get-api-key
# To use OpenStreetMap tiles, set `engine` to 2.
# To use OpenStreetMap on a high traffic site, set `engine` to 3 and enter your API key that can be obtained here:
# https://www.mapbox.com/studio/account/tokens
#
# Map provider:
# 0: No map
# 1: Google Maps
# 2: OpenStreetMap (Mapnik)
# 3: OpenStreetMap (Mapbox)
engine = 1
api_key = ""
zoom = 15
You are injecting three strings. I think you want to inject one string and two integers.
HUGO_PARAMS_MAP='{"engine":1,"api_key":"12345","zoom":15}' hugo server
With this, map.engine and map.zoom will be float64. When you set them in params.toml, the type is int64, so this may not work. You might have to cast them to int within the theme.
Stupid question, but how would I go about recasting to int64? standard go would just be to call {{ int64() }}, but that doesn’t work. Or maybe I’m doing it wrong.
I’ve been digging further and found that a lot of the Java Scripts needed for my site aren’t loaded when I inject parameters in the configuration. I’ll be honest, I have no idea why only a subset of the defined JS would ever be loaded, or what could coarse it.