Closed nealmcb closed 1 year ago
We can use jinja2-time to get the current year with {% now 'utc', '%Y' %}
as in year_to
. I'm not sure how to turn that in cookiecutter.json into a list of options [X, X-1, X-2, ...] going back a few years. Failing that, I guess we could do free-form text input with that as the default, like year_to
. Not sure if we'd then need to sanity-check that the input looked like a year.
I just added the year meanwhile a better way is studied.
I'm not absolutely sure whether cookiecutter allows the definition of new/custom filter functions, then it can be simplified.
But a loop might work in combination with range(2021, 2004, -1)
.
So:
[{% for y in range(year, 2004, -1) -%}{%- if loop.index > 1 %},{% endif %}"{{ y }}"{%- endfor %}]
If numbers work, then (json?):
{{ range(2021, 2005, -1) | list }}
Now, just somehow get the year filter included...
Ooof. I think I over-engineered year_from. I changed it to be a simple input like year_to is.
Error:
Seems like something that should be calculated, or even allowed to be in the future and free-form.
This is currently defined in
cookiecutter.json