Skip to content

Commit 2e7629e

Browse files
authored
docs: restructure context vars, add undocumented ones (#1856)
1 parent 19156ee commit 2e7629e

File tree

2 files changed

+56
-24
lines changed

2 files changed

+56
-24
lines changed

docs/creating.md

+55-24
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,58 @@ their usage.
7575
7676
In addition to
7777
[all the features Jinja supports](https://jinja.palletsprojects.com/en/3.1.x/templates/),
78-
Copier includes:
79-
80-
- All functions and filters from
81-
[jinja2-ansible-filters](https://gitlab.com/dreamer-labs/libraries/jinja2-ansible-filters/).
82-
83-
- This includes the `to_nice_yaml` filter, which is used extensively in our
84-
context.
85-
86-
- `_copier_answers` includes the current answers dict, but slightly modified to make
87-
it suitable to [autoupdate your project safely][the-copier-answersyml-file]:
88-
- It doesn't contain secret answers.
89-
- It doesn't contain any data that is not easy to render to JSON or YAML.
90-
- It contains special keys like `_commit` and `_src_path`, indicating how the last
91-
template update was done.
92-
- `_copier_conf` includes a representation of the current Copier
93-
<!-- prettier-ignore -->
94-
[Worker][copier.main.Worker] object, also slightly modified:
95-
- It only contains JSON-serializable data.
96-
- You can serialize it with `{{ _copier_conf|to_json }}`.
97-
- ⚠️ It contains secret answers inside its `.data` key.
98-
- Modifying it doesn't alter the current rendering configuration.
99-
- It contains the current commit hash from the template in
100-
`{{ _copier_conf.vcs_ref_hash }}`.
101-
- Contains Operating System-specific directory separator under `sep` key.
78+
Copier provides all functions and filters from
79+
[jinja2-ansible-filters](https://gitlab.com/dreamer-labs/libraries/jinja2-ansible-filters/).
80+
This includes the `to_nice_yaml` filter, which is used extensively in our context.
81+
82+
## Variables (global)
83+
84+
The following variables are always available in Jinja templates:
85+
86+
### `_copier_answers`
87+
88+
`_copier_answers` includes the current answers dict, but slightly modified to make it
89+
suitable to [autoupdate your project safely][the-copier-answersyml-file]:
90+
91+
- It doesn't contain secret answers.
92+
- It doesn't contain any data that is not easy to render to JSON or YAML.
93+
- It contains special keys like `_commit` and `_src_path`, indicating how the last
94+
template update was done.
95+
96+
### `_copier_conf`
97+
98+
`_copier_conf` includes a representation of the current Copier
99+
[Worker][copier.main.Worker] object, also slightly modified:
100+
101+
- It only contains JSON-serializable data.
102+
- You can serialize it with `{{ _copier_conf|to_json }}`.
103+
- ⚠️ It contains secret answers inside its `.data` key.
104+
- Modifying it doesn't alter the current rendering configuration.
105+
106+
Furthermore, the following keys are added:
107+
108+
#### `os` { #\_copier_conf.os }
109+
110+
The detected operating system, either `"linux"`, `"macos"`, `"windows"` or `None`.
111+
112+
#### `sep` { #\_copier_conf.sep }
113+
114+
The operating system-specific directory separator.
115+
116+
#### `vcs_ref_hash` { #\_copier_conf.vcs_ref_hash }
117+
118+
The current commit hash from the template.
119+
120+
### `_copier_python`
121+
122+
The absolute path of the Python interpreter running Copier.
123+
124+
### `_folder_name`
125+
126+
The name of the project root directory.
127+
128+
## Variables (context-specific)
129+
130+
Some rendering contexts provide variables unique to them:
131+
132+
- [`migrations`](configuring.md#migrations)

mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ extra_css:
5757

5858
markdown_extensions:
5959
- admonition
60+
- attr_list
6061
- pymdownx.highlight:
6162
use_pygments: true
6263
- pymdownx.superfences:

0 commit comments

Comments
 (0)