How to detect `buildFuture` from within template

I’d like to do stuff in a template conditional on whether Hugo is configured to build future content (i.e. the --buildFuture CLI flag is set or buildFuture = true is set in the config).

I searched this forum, the GitHub issue tracker as well as the general web, but couldn’t find a simple answer on how to detect whether Hugo is run with buildFuture set or not.

If Hugo would simply set an environment variable HUGO_BUILD_FUTURE when run with buildFuture, I would already be happy…

Anything I’m missing or should I simply open a feature request on GitHub? (Unfortunately, my Golang skills are zero.)

@bep Care to comment on this? Would appreciate it. :upside_down_face:

You could create a dummy page with a date well into the future…


title = 'Future'
date = 2500-10-07T16:08:34-07:00
draft = false
  list = 'never'
  render = 'never'

Then do something like this in your template…

{{ $buildFuture := false }}
{{ if .GetPage "/" }}
  {{ $buildFuture = true }}
{{ end }}

@jmooring Thanks a lot for the workaround, works flawless!

Still, I think a simple HUGO_BUILD_FUTURE env var would be awesome…

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.