Evaluating hugo build (runtime) flags in templates


How can I test the value of a hugo build flag from a template?
For example, I want to write a shortcode that behaves differently depending on whether hugo was run with the --buildDrafts (or -D) flag.
(I know how to use $.Page.IsDraft to check whether a given page sets draft to true, but this is not what I’m after here.)


You can not, but you can get environment vars from templates, which may be helpful.


You mean that instead of or in addition to setting the hugo build flag I can set an equivalent environment variable, and then read this variable from my template/shortcode? That could work.
How do I read an environment variable in the template?