Skip to content

Commit 3065bf3

Browse files
author
metworkbot
committed
build: sync common files from github_organization_management repository
1 parent 1fb8c13 commit 3065bf3

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,37 @@
1212

1313

1414

15+
## What is it ?
16+
17+
This is a [jinja2](http://jinja.pocoo.org/) extension to access to system
18+
environment variables. It is usefull if you have dynamically generated
19+
variable names.
20+
21+
## Syntax
22+
23+
The syntax is `{{ 'ENV_VAR'|getenv }}` to access to the `ENV_VAR` environment
24+
variable. Don't forget the quotes around `ENV_VAR` !
25+
26+
If you want to provide a default value to avoid an exception if the corresponding
27+
environment variable does not exist, you can use the following syntax:
28+
`{{ 'ENV_VAR'|getenv('default_value') }}`.
29+
30+
## Examples
31+
32+
```python
33+
34+
from jinja2 import Template, Environment
35+
36+
# We load the extension in a jinja2 Environment
37+
env = Environment(extensions=["jinja2_getenv_extension.GetenvExtension"])
38+
39+
# For the example, we use a template from a simple string
40+
template = env.from_string("the value of HOME environment variable is: "
41+
"{{ 'HOME'|getenv }}")
42+
result = template.render()
43+
44+
# [...]
45+
```
1546

1647

1748

0 commit comments

Comments
 (0)