How to use Netlify envornment variable in template

I am using Hugo-universal-theme, github, and netlify. Everything works great, except I cannot use my Google Maps API key in the config.toml file because then it will be exposed to the public via github. Netlify has the ability to create environment variables, so I created one called GOOGLEMAPS_API_KEY with my key in it. How do I use that in the config.toml. If I simply try


I get an error relating to the params.googleMapsApiKey.

Thanks, Roger

Hi Roger,

Have you seen this article?

It describes how to successfully USE the environment variable; TL;DR it’s usable at BUILD TIME ONLY, and during your build you’d put it into your static pages, since it isn’t available at BROWSE TIME for interpolation.

If you need to hide the API key, consider a function such as this one to “proxy” to that API with that key:

1 Like