Hugo conditional params


In my nav bar I would like to set a logout URL conditionally according to the environment.Its a dockerize app and I ve ENVIROMENT variable but ı could not find a way to use that variable here.

I’ve a single config.toml and I added below param as below.How can I do this conditionally?

logoutURL = “

	<a href="{{ .Site.Params.logoutURL }}" class="btn btn-dark"><i class="fas fa-sign-out-alt fa-lg"></i></a>


We can get an environment variable with getenv | Hugo

{{ $enviroment := getenv "ENVIRONMENT" }}
{{ if eq $enviroment "develop" }}
  <a href="{{ $.Site.Params.logoutURL }}">Logout</a>
{{ else }}
{{ end }}

@peaceiris cool… it gets the system env that we pass to container, am I right?

Yes. When we run Hugo on a Docker container, we need to pass an env from a host OS with some kind of method.

There is also hugo.Environment and hugo.IsProduction (both of which reads values from HUGO_ENV or HUGO_ENVIRONMENT + the hugo -e someenvironment flag.