1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
Boolean Variables
-----------------
.. versionadded:: 2.2.0
Boolean variables are used for answering True/False questions.
Basic Usage
~~~~~~~~~~~
Boolean variables are regular key / value pairs, but with the value being
``True``/``False``.
For example, if you provide the following boolean variable in your
``cookiecutter.json``::
{
"run_as_docker": true
}
you will get the following user input when running Cookiecutter::
run_as_docker [True]:
User input will be parsed by :func:`~cookiecutter.prompt.read_user_yes_no`. The
following values are considered as valid user input:
- ``True`` values: "1", "true", "t", "yes", "y", "on"
- ``False`` values: "0", "false", "f", "no", "n", "off"
The above ``run_as_docker`` boolean variable creates ``cookiecutter.run_as_docker``,
which can be used like this::
{%- if cookiecutter.run_as_docker -%}
# In case of True add your content here
{%- else -%}
# In case of False add your content here
{% endif %}
Cookiecutter is using `Jinja2's if conditional expression <https://jinja.palletsprojects
.com/en/latest/templates/#if>`_ to determine the correct ``run_as_docker``.
Input Validation
~~~~~~~~~~~~~~~~
If a non valid value is inserted to a boolean field, the following error will be printed:
.. code-block:: bash
run_as_docker [True]: docker
Error: docker is not a valid boolean
|