https://github.com/metwork-framework/jinja2_getenv_extension
a jinja2 extension to access to system environment variables
https://github.com/metwork-framework/jinja2_getenv_extension
autoreadme github-actions integration-level-3 jinja2 jinja2-extension
Last synced: 2 months ago
JSON representation
a jinja2 extension to access to system environment variables
- Host: GitHub
- URL: https://github.com/metwork-framework/jinja2_getenv_extension
- Owner: metwork-framework
- License: bsd-3-clause
- Created: 2018-10-16T08:40:38.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-11-25T11:54:26.000Z (7 months ago)
- Last Synced: 2025-04-20T07:06:32.533Z (3 months ago)
- Topics: autoreadme, github-actions, integration-level-3, jinja2, jinja2-extension
- Language: Python
- Homepage:
- Size: 52.7 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# jinja2_getenv_extension
[//]: # (automatically generated from https://github.com/metwork-framework/github_organization_management/blob/master/common_files/README.md)
**Status (master branch)**
[](https://github.com/metwork-framework/jinja2_getenv_extension/actions?query=workflow%3ACI+branch%3Amaster)
[](https://github.com/metwork-framework/resources/blob/master/badges/maintained.svg)## What is it ?
This is a [jinja2](http://jinja.pocoo.org/) extension to access to system
environment variables. It is usefull if you have dynamically generated
variable names.## Syntax
The syntax is `{{ 'ENV_VAR'|getenv }}` to access to the `ENV_VAR` environment
variable. Don't forget the quotes around `ENV_VAR` !If you want to provide a default value to avoid an exception if the corresponding
environment variable does not exist, you can use the following syntax:
`{{ 'ENV_VAR'|getenv('default_value') }}`.## Examples
```python
from jinja2 import Template, Environment
# We load the extension in a jinja2 Environment
env = Environment(extensions=["jinja2_getenv_extension.GetenvExtension"])# For the example, we use a template from a simple string
template = env.from_string("the value of HOME environment variable is: "
"{{ 'HOME'|getenv }}")
result = template.render()# [...]
```## Contributing guide
See [CONTRIBUTING.md](CONTRIBUTING.md) file.
## Code of Conduct
See [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) file.
## Sponsors
*(If you are officially paid to work on MetWork Framework, please contact us to add your company logo here!)*
[](http://www.meteofrance.com)