How to access config [params] map from command line

I am using Hugo to build 3 versions of a site: one for internal use, one for external use, and one for local, file-system access. Each one requires slightly different configurations. In an effort to avoid duplicating shared settings in 3 different config.toml files, I’m trying to use a single config.toml and pass in the specific commands that are different to our CI system at build time. I’m close to getting this to work, but I’m stuck with how to access parameters defined in my config.toml [params] block.

Has anyone figured out how to access hugo [params] from a command line?

For example, here is a simplified version of my config.toml file:

title = "Developer Portal"
theme = "theme-public"

  internal = false
  description = "Public site"

When I run the command below, the TITLE and THEME config settings are set correctly, but the INTERNAL param is unchanged.

env HUGO_TITLE="Developer Portal - Internal build" HUGO_THEME="theme-internal" HUGO_PARAMS.INTERNAL=true hugo --cleanDestinationDir

I also tried a few different variations of the above without success. For example:

env HUGO_TITLE="Developer Portal - Internal build" HUGO_THEME="theme-internal" HUGO_PARAMS_INTERNAL=true hugo --cleanDestinationDir

I took a look at Viper, but I couldn’t figure out how to use it to solve this problem. Has anyone else tried to do something like this? If so, thanks for any tips!


I ran into the same issue. Thanks for any tips and hints?

I don’t know.

I don’t have a solution - but found something:

With this config.toml:


I get what is expected:

$ hugo config | grep testenv
params = map[hello:world testenv:bar]

Overriding works for the hugo config command:

$ env HUGO_PARAMS.TESTENV="foo" hugo config | grep testenv
params = map[hello:world testenv:foo]

But .Site.Params.testenv has the value “bar” for:

env HUGO_PARAMS.TESTENV="foo" hugo
env HUGO_PARAMS.TESTENV="foo" hugo server

Testing done with:

Hugo Static Site Generator v0.33 linux/amd64 BuildDate: 
1 Like