File: nested_config_files.rst

package info (click to toggle)
cookiecutter 2.6.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,780 kB
  • sloc: python: 6,097; makefile: 113; sh: 8
file content (86 lines) | stat: -rw-r--r-- 2,419 bytes parent folder | download
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
.. _nested-config-files:

Nested configuration files
--------------------------

*New in Cookiecutter 2.5.0*

If you wish to create a hierarchy of templates and use cookiecutter to choose among them,
you need just to specify the key ``templates`` in the main configuration file to reach
the other ones.

Let's imagine to have the following structure::

    main-directory/
        ├── project-1
        │   ├── cookiecutter.json
        │   ├── {{cookiecutter.project_slug}}
        |	│   ├── ...
        ├── package
        │   ├── cookiecutter.json
        │   ├── {{cookiecutter.project_slug}}
        |	│   ├── ...
        └── cookiecutter.json

It is possible to specify in the main ``cookiecutter.json`` how to reach the other
config files as follows:

.. code-block:: JSON

    {
        "templates": {
            "project-1": {
                "path": "./project-1",
                "title": "Project 1",
                "description": "A cookiecutter template for a project"
            },
            "package": {
                "path": "./package",
                "title": "Package",
                "description": "A cookiecutter template for a package"
            }
        }
    }

Then, when ``cookiecutter`` is launched in the main directory it will ask to choose
among the possible templates:

.. code-block::

    Select template:
    1 - Project 1 (A cookiecutter template for a project)
    2 - Package (A cookiecutter template for a package)
    Choose from 1, 2 [1]:

Once a template is chosen, for example ``1``, it will continue to ask the info required by
``cookiecutter.json`` in the ``project-1`` folder, such as ``project-slug``


Old Format
++++++++++

*New in Cookiecutter 2.2.0*

In the main ``cookiecutter.json`` add a `template` key with the following format:

.. code-block:: JSON

    {
        "template": [
            "Project 1 (./project-1)",
            "Project 2 (./project-2)"
        ]
    }

Then, when ``cookiecutter`` is launched in the main directory it will ask to choose
among the possible templates:

.. code-block::

    Select template:
    1 - Project 1 (./project-1)
    2 - Project 2 (./project-2)
    Choose from 1, 2 [1]:

Once a template is chosen, for example ``1``, it will continue to ask the info required by
``cookiecutter.json`` in the ``project-1`` folder, such as ``project-slug``