I have no idea how else to say it. It seems that you don’t yet understand the problem. Pondering it over further.
Can HUGO_ENV be both “testing” and “production” at the same time? On the same server, under the same user? …
I’ll repeat again, should it help.
There is 1 server. It hosts 2 domains.
The server is my “production server”, so I would naturally login, and do export HUGO_ENV=“production”.
{{ if eq (getenv “HUGO_ENV”) “production” }} do stuff {{end }}
Then I build my site with this code. Since the ENV VAR has been set to production, it will build with analytics. site.com
Now, this server also houses test.site.com (testing branch).
So, when you biuld the dev.site.com from a testing branch in a diff doc_root, since ENV VAR is “production” it will still build with Analytics.
So, if you set export HUGO_ENV=“testing”, it will build without analytics for dev.site.com.
If you now try to build your site.com it expects “production”, it finds “testing” and builds without analytics.
I hope that helps to understand further the problem w/ this approach on a single server.
One could have two users on the machine.
hugoprod, and hugotest.
login as hugoprod and export HUGO_ENV="produciton"
login as hugotest and export HUGO_ENV=“testing”
hugoprod pulls from master
hugotest pulls from testing
Each user now has their correct env variable set.
What you suggest ONLY works for a single user on a single server.
It’s a method different than using a JS check, but it fails on multienv. systems.
Env. is one. You can’t have multiple values for the same ENV VAR under the same user. One env. One value. That’s how it works.