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…

content/future.md

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

Then do something like this in your template…

{{ $buildFuture := false }}
{{ if .GetPage "/future.md" }}
  {{ $buildFuture = true }}
{{ end }}
2 Likes

@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.