diff options
Diffstat (limited to 'docs/content/en/functions/getenv.md')
-rw-r--r-- | docs/content/en/functions/getenv.md | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/docs/content/en/functions/getenv.md b/docs/content/en/functions/getenv.md index 9ada0d031..f7f71d35c 100644 --- a/docs/content/en/functions/getenv.md +++ b/docs/content/en/functions/getenv.md @@ -1,30 +1,43 @@ --- title: getenv -description: Returns the value of an environment variable. +description: Returns the value of an environment variable, or an empty string if the environment variable is not set. date: 2017-02-01 publishdate: 2017-02-01 -lastmod: 2017-02-01 +lastmod: 2021-11-26 categories: [functions] menu: docs: parent: "functions" keywords: [] -signature: ["getenv VARIABLE"] +signature: ["os.Getenv VARIABLE", "getenv VARIABLE"] workson: [] hugoversion: relatedfuncs: [] deprecated: false aliases: [] --- +Examples: -Takes a string containing the name of the variable as input. Returns -an empty string if the variable is not set, otherwise returns the -value of the variable. - +```go-html-template +{{ os.Getenv "HOME" }} --> /home/victor +{{ os.Getenv "USER" }} --> victor ``` -{{ getenv "HOME" }} + +You can pass values when building your site: + +```bash +MY_VAR1=foo MY_VAR2=bar hugo + +OR + +export MY_VAR1=foo +export MY_VAR2=bar +hugo ``` -{{% note %}} -In Unix-like environments, the variable must also be exported in order to be seen by `hugo`. -{{% /note %}} +And then retrieve the values within a template: + +```go-html-template +{{ os.Getenv "MY_VAR1" }} --> foo +{{ os.Getenv "MY_VAR2" }} --> bar +``` |