How to get configuration environment being used in template?

Hi Everyone,
I created a directory called: “staging” inside my: “config” folder. The documentation says that when Hugo is run without any flags its environment defaults to: “production”, when it is run with: Hugo server the environment is: “development”.

I would like to check what kind of environment is currently in context, for example:
Hugo --environment staging

How can I check if it is “staging” or “production”?
Using: {{ if eq (getenv “HUGO_ENV”) “production” -}} does nto work, for I guess it is for checking system environment variables.

Thanks for help in advance,
Pawel

{{ .Hugo.Environment }}

See: https://gohugo.io/variables/hugo/

Thank you Maiki,
Addint a note due to the upcoming change in Hugo’s API:
hugo.Environment will be the correct call.
P.S.: Unless, there will be some future change in the API itself.

1 Like