cookiecutter / cookiecutter/cookiecutter

Feature-Request: Templates in context variables should support boolean values

Open
#2,025 11 comments 1 reaction 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.