Using variables in hugo new post/sectionName/title

pretty straightforward, I want to use parts of the hugo new post command to populate the frontmatter.

Can this be done?

I have to get better at documenting the stuff I create, but I think what you want is here:

Or, maybe I misunderstood – which makes it “not straight forward …”

Also (and this I will have to remember to get into the documentation).

If you want to pass random arguments to use in the archetype templates, you can use the getenv template func.


MYVAR=foo hugo new post/

And in archetype template:

{{ getenv "MYVAR" }}

Note that setting of the OS environment variables inline like that may vary between OSes.

Thank you @bep, that’s exactly what I needed. :slight_smile:

The end result was this little script:


# usage STORY

export STORY=$1

hugo new stories/$STORY/$2
1 Like