Replies: 1 comment 1 reply
-
|
I think you could create a custom Jinja extension that loads the choices from your data source. For example, a fictitious Jinja extension could register a filter _jinja_extensions:
- your_http_extension.HTTPExtension
dynamic_choices:
type: str
choices: |
{% for choice in 'https://api.example.com/choices' | http_get | from_json -%}
- "{{ choice }}"
{% endfor %}With copier-templates-extensions, you can also load a Jinja extension from a local file instead of a package. Note that Copier's update algorithm currently relies on replaying a fresh project from the old version of a template. For this to work correctly, project generation must be reproducible, so your dynamic choices must be the same when generating the project for the first time and when replaying the old copy during an update. This may change in the future, but it's a nontrivial problem to solve. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to have dynamic options for the "choices" attribute. Instead of manually listing every option the user can select, I want to fetch the options from what a specific script returns. The approaches I researched and found (ContextHooks and via "_tasks") didn’t work, because the user always had to respond/select the options first, and only afterward the options I wanted to fetch would be executed by those methods.
I would like to know if there is any way to do this with the tools we have (ContextHooks, _tasks, _external_data).
Beta Was this translation helpful? Give feedback.
All reactions