Skip to content

Commit 1fb8c13

Browse files
committed
build: restore README file
1 parent 66bf458 commit 1fb8c13

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

.metwork-framework/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## What is it ?
2+
3+
This is a [jinja2](http://jinja.pocoo.org/) extension to access to system
4+
environment variables. It is usefull if you have dynamically generated
5+
variable names.
6+
7+
## Syntax
8+
9+
The syntax is `{% raw %}{{ 'ENV_VAR'|getenv }}{% endraw %}` to access to the `ENV_VAR` environment
10+
variable. Don't forget the quotes around `ENV_VAR` !
11+
12+
If you want to provide a default value to avoid an exception if the corresponding
13+
environment variable does not exist, you can use the following syntax:
14+
`{% raw %}{{ 'ENV_VAR'|getenv('default_value') }}{% endraw %}`.
15+
16+
## Examples
17+
18+
```python
19+
20+
from jinja2 import Template, Environment
21+
22+
# We load the extension in a jinja2 Environment
23+
env = Environment(extensions=["jinja2_getenv_extension.GetenvExtension"])
24+
25+
# For the example, we use a template from a simple string
26+
template = env.from_string("the value of HOME environment variable is: "
27+
"{% raw %}{{ 'HOME'|getenv }}{% endraw %}")
28+
result = template.render()
29+
30+
# [...]
31+
```
32+

0 commit comments

Comments
 (0)