Boolean variables are a fundamental building block for creating interactive project generation experiences with DKCutter. They allow you to present users with yes-or-no questions, enabling you to tailor project setups based on their preferences.
Boolean variables are defined within your dkcutter.json
configuration file and can be either simple boolean
values (true or false) or objects with specific properties.
Consider the following dkcutter.json
snippet:
In this example:
"runInstall"
is the name of the boolean variable.true
indicates that the installation process should be run by default.When the user encounters this variable during project generation, they'll see a prompt:
The user can confirm (No / Yes) to proceed with the installation or choose not to (No).
Once the user makes a selection, the chosen value becomes accessible within your project templates as dkcutter.runInstall
. You can leverage this value with conditional statements to control the flow of your templates.
Here's how you might use the dkcutter.runInstall
variable in a template:
This example utilizes a Nunjucks conditional statement ({% if...%}
) to check the value of dkcutter.runInstall
. If it's true
(user confirmed installation), the installation commands within the block will be executed.
true
and false
are the most common values, boolean variables defined as objects can provide more flexibility. Refer to the DKCutter documentation for details on object-based boolean variables.By effectively using boolean variables, you can streamline your project generation process and cater to user preferences during DKCutter project creation.