mirror of
https://github.com/copier-org/copier.git
synced 2025-05-05 23:42:55 +00:00
docs: restructure context vars, add undocumented ones (#1856)
This commit is contained in:
parent
19156ee3be
commit
2e7629e3d6
@ -75,27 +75,58 @@ their usage.
|
|||||||
|
|
||||||
In addition to
|
In addition to
|
||||||
[all the features Jinja supports](https://jinja.palletsprojects.com/en/3.1.x/templates/),
|
[all the features Jinja supports](https://jinja.palletsprojects.com/en/3.1.x/templates/),
|
||||||
Copier includes:
|
Copier provides all functions and filters from
|
||||||
|
|
||||||
- All functions and filters from
|
|
||||||
[jinja2-ansible-filters](https://gitlab.com/dreamer-labs/libraries/jinja2-ansible-filters/).
|
[jinja2-ansible-filters](https://gitlab.com/dreamer-labs/libraries/jinja2-ansible-filters/).
|
||||||
|
This includes the `to_nice_yaml` filter, which is used extensively in our context.
|
||||||
|
|
||||||
- This includes the `to_nice_yaml` filter, which is used extensively in our
|
## Variables (global)
|
||||||
context.
|
|
||||||
|
The following variables are always available in Jinja templates:
|
||||||
|
|
||||||
|
### `_copier_answers`
|
||||||
|
|
||||||
|
`_copier_answers` includes the current answers dict, but slightly modified to make it
|
||||||
|
suitable to [autoupdate your project safely][the-copier-answersyml-file]:
|
||||||
|
|
||||||
- `_copier_answers` includes the current answers dict, but slightly modified to make
|
|
||||||
it suitable to [autoupdate your project safely][the-copier-answersyml-file]:
|
|
||||||
- It doesn't contain secret answers.
|
- It doesn't contain secret answers.
|
||||||
- It doesn't contain any data that is not easy to render to JSON or YAML.
|
- It doesn't contain any data that is not easy to render to JSON or YAML.
|
||||||
- It contains special keys like `_commit` and `_src_path`, indicating how the last
|
- It contains special keys like `_commit` and `_src_path`, indicating how the last
|
||||||
template update was done.
|
template update was done.
|
||||||
- `_copier_conf` includes a representation of the current Copier
|
|
||||||
<!-- prettier-ignore -->
|
### `_copier_conf`
|
||||||
|
|
||||||
|
`_copier_conf` includes a representation of the current Copier
|
||||||
[Worker][copier.main.Worker] object, also slightly modified:
|
[Worker][copier.main.Worker] object, also slightly modified:
|
||||||
|
|
||||||
- It only contains JSON-serializable data.
|
- It only contains JSON-serializable data.
|
||||||
- You can serialize it with `{{ _copier_conf|to_json }}`.
|
- You can serialize it with `{{ _copier_conf|to_json }}`.
|
||||||
- ⚠️ It contains secret answers inside its `.data` key.
|
- ⚠️ It contains secret answers inside its `.data` key.
|
||||||
- Modifying it doesn't alter the current rendering configuration.
|
- Modifying it doesn't alter the current rendering configuration.
|
||||||
- It contains the current commit hash from the template in
|
|
||||||
`{{ _copier_conf.vcs_ref_hash }}`.
|
Furthermore, the following keys are added:
|
||||||
- Contains Operating System-specific directory separator under `sep` key.
|
|
||||||
|
#### `os` { #\_copier_conf.os }
|
||||||
|
|
||||||
|
The detected operating system, either `"linux"`, `"macos"`, `"windows"` or `None`.
|
||||||
|
|
||||||
|
#### `sep` { #\_copier_conf.sep }
|
||||||
|
|
||||||
|
The operating system-specific directory separator.
|
||||||
|
|
||||||
|
#### `vcs_ref_hash` { #\_copier_conf.vcs_ref_hash }
|
||||||
|
|
||||||
|
The current commit hash from the template.
|
||||||
|
|
||||||
|
### `_copier_python`
|
||||||
|
|
||||||
|
The absolute path of the Python interpreter running Copier.
|
||||||
|
|
||||||
|
### `_folder_name`
|
||||||
|
|
||||||
|
The name of the project root directory.
|
||||||
|
|
||||||
|
## Variables (context-specific)
|
||||||
|
|
||||||
|
Some rendering contexts provide variables unique to them:
|
||||||
|
|
||||||
|
- [`migrations`](configuring.md#migrations)
|
||||||
|
@ -57,6 +57,7 @@ extra_css:
|
|||||||
|
|
||||||
markdown_extensions:
|
markdown_extensions:
|
||||||
- admonition
|
- admonition
|
||||||
|
- attr_list
|
||||||
- pymdownx.highlight:
|
- pymdownx.highlight:
|
||||||
use_pygments: true
|
use_pygments: true
|
||||||
- pymdownx.superfences:
|
- pymdownx.superfences:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user