Hugo conditional params

Hi,

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?

[params]
logoutURL = “https://example.com/redirect/oidcLogout

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

Regards,

We can get an environment variable with getenv | Hugo

{{ $enviroment := getenv "ENVIRONMENT" }}
{{ if eq $enviroment "develop" }}
  <a href="{{ $.Site.Params.logoutURL }}">Logout</a>
{{ else }}
  <p>Production</p>
{{ 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.