cookiecutter / cookiecutter/cookiecutter
Feature-Request: Templates in context variables should support boolean values
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 25.1k
- Forks
- 2.3k
- PR merge metrics
- No merged PRs in 30d
Description
- Cookiecutter version: 2.6.0
- Python version: 3.9.16
- Operating System: RHEL 8
This issue is a reopening of #1738.
Description:
As described here, we expect template authors to be able to reuse values of previous keys from cookiecutter.json, but currently that is not possible if you are working with boolean values. I believe it would be very important to support this use case or describe an alternative way to do it in docs. Example:
cookiecutter.json:
{
"likes_potatoes": false,
"likes_mashed_potatoes": "{{ cookiecutter.likes_potatoes }}"
}
Template example using above variables:
#!/bin/bash
{% if cookiecutter.likes_mashed_potatoes %}
echo "I like mashed potatoes!"
{% endif %}
The echo "I like mashed potatoes" line always renders, even when likes_potatoes is false.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the example with the shown cookiecutter.json values and template conditional, then inspect the current template-in-context rendering behavior. Done means a boolean value reused through a context variable remains boolean, so the false value prevents the echo from rendering, with coverage for this example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100