How to check if a Hugo site is in development or production

I wanted to render the hugo navigation differently on my development (internal) server and my production (public) server. This is how I did it for partials…

Finding out the envionment

Hugo has a couple of settings we can check

{{ hugo.Environment }} returns "development" or "production"
{{ hugo.IsProduction }} returns true or false

Conditional Rendering

{{ if hugo.IsProduction }}
  I render when in production
{{ end }}

{{ if not hugo.IsProduction }}
  I render when not in production
{{ end }}

Setting the environment

Use the –environment flag when starting hugo

Production Deployment script

hugo --environment development ...

Development docker compose file

hugo --environment development ...