hugo/docs/content/en/functions/os/Getenv.md
2023-10-20 09:43:56 +02:00

1.1 KiB

title linkTitle description categories keywords menu function relatedFunctions aliases
os.Getenv getenv Returns the value of an environment variable, or an empty string if the environment variable is not set.
functions
docs
parent
functions
aliases returnType signatures
getenv
string
os.Getenv VARIABLE
os.FileExists
os.Getenv
os.ReadDir
os.ReadFile
os.Stat
/functions/getenv

Examples:

{{ os.Getenv "HOME" }} → /home/victor
{{ os.Getenv "USER" }} → victor

You can pass values when building your site:

MY_VAR1=foo MY_VAR2=bar hugo

OR

export MY_VAR1=foo
export MY_VAR2=bar
hugo

And then retrieve the values within a template:

{{ os.Getenv "MY_VAR1" }} → foo
{{ os.Getenv "MY_VAR2" }} → bar

With Hugo v0.91.0 and later, you must explicitly allow access to environment variables. For details, review Hugo's Security Policy. By default, environment variables beginning with HUGO_ are allowed when using the os.Getenv function.