copier-org / copier

Library and command-line utility for rendering projects templates.
https://readthedocs.org/projects/copier/
MIT License
1.92k stars 173 forks source link

templates / variables in `choices` #1359

Open exitcode0 opened 11 months ago

exitcode0 commented 11 months ago

Describe the problem

I'm new to both copier and jinja so perhaps I just need to be pointed in the correct direction

I'm trying to construct the choices option on a question

Template

question_choices:
    default: ["A","B"]
    when: false

actual_question:
    help: "the cake is a lie"
    choices: ["{{question_choices}}"]
question_choices:
    default: ["A","B"]
    when: false

actual_question:
    help: "the cake is a lie"
    choices: "{% for item in {{question_choices}} -%}  - 'name': '{{item}}'{% endfor %}"

To Reproduce

No response

Logs

No response

Expected behavior

hoping to be able to generate the valid choices at run time, perhaps via script

Screenshots/screencasts/logs

No response

Operating system

macOS

Operating system distribution and version

Ventura 13.6

Copier version

copier 8.3.0

Python version

Python 3.11.5

Installation method

pip+git

Additional context

No response

sisp commented 11 months ago

I'm afraid what you'd like to do is currently not possible. See also #1193 for a previous discussion.