# How to use Netlify envornment variable in template

**URL:** <https://discourse.gohugo.io/t/how-to-use-netlify-envornment-variable-in-template/20622>\
**Category:** support\
**Created:** [September 6, 2019, 3:23pm UTC](https://discourse.gohugo.io/t/how-to-use-netlify-envornment-variable-in-template/20622 "2019-09-06T15:23:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogerjbos](https://avatars.discourse-cdn.com/v4/letter/r/82dd89/32.png) [@rogerjbos](https://discourse.gohugo.io/u/rogerjbos)\
**Post date:** [September 6, 2019, 3:23pm UTC](https://discourse.gohugo.io/t/how-to-use-netlify-envornment-variable-in-template/20622/1 "2019-09-06T15:23:58Z")

</div>

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

```auto
googleMapsApiKey = GOOGLEMAPS_API_KEY

```

I get an error relating to the params.googleMapsApiKey.

Thanks, Roger

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [September 6, 2019, 4:10pm UTC](https://discourse.gohugo.io/t/how-to-use-netlify-envornment-variable-in-template/20622/2 "2019-09-06T16:10:54Z")

</div>

Hi @rogerjbos. You’re close. You’ll wanna get your env var from inside the template you need it in. See this function:

> **[getenv](https://gohugo.io/functions/getenv/#readout)**
>
> Returns the value of an environment variable.

---

<div class="post-metadata">

**Author:** ![rogerjbos](https://avatars.discourse-cdn.com/v4/letter/r/82dd89/32.png) [@rogerjbos](https://discourse.gohugo.io/u/rogerjbos)\
**Post date:** [September 6, 2019, 4:41pm UTC](https://discourse.gohugo.io/t/how-to-use-netlify-envornment-variable-in-template/20622/3 "2019-09-06T16:41:18Z")

</div>

Thanks for the suggestion, but maybe I am not interpreting the docs correctly. Trying the following in my config.toml file

```auto
googleMapsApiKey = {{ getenv "GOOGLEMAPS_API_KEY" }}

```

gives an error that bare keys cannot contain “{”. I need a newbie explanation.

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [September 6, 2019, 4:48pm UTC](https://discourse.gohugo.io/t/how-to-use-netlify-envornment-variable-in-template/20622/4 "2019-09-06T16:48:17Z")

</div>

Let me clarify. Don’t use that function in your config file. Use it in your template. Aka `layouts/_default/baseof.html` or something like that
