https://github.com/vd2org/jinja2yaml
YamlLoader for jinja2
https://github.com/vd2org/jinja2yaml
jinja2 jinja2-extension jinja2-template jinja2-yaml pyyaml template
Last synced: 3 months ago
JSON representation
YamlLoader for jinja2
- Host: GitHub
- URL: https://github.com/vd2org/jinja2yaml
- Owner: vd2org
- License: mit
- Created: 2024-02-26T10:09:47.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-02-26T13:12:37.000Z (over 2 years ago)
- Last Synced: 2025-12-19T20:18:31.883Z (6 months ago)
- Topics: jinja2, jinja2-extension, jinja2-template, jinja2-yaml, pyyaml, template
- Language: Python
- Homepage:
- Size: 32.2 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jinja2loader
YamlLoader is a template loader for jinja2 template framework.
It loads templates from yaml-files. Useful when you need to
store many small templates in one file.
## Install
```bash
pip install jinja2yaml
```
### Related packages:
- [Collection of utils for jinja2](https://github.com/vd2org/jinja2utils)
#### Usage:
```yaml
# templates.yaml
home:
welcome: |
Welcome, {{username}}!
goodbye: |
Goodbye, {{username}}!
```
```python
# main.py
from jinja2 import Environment
from jinja2yaml import YamlLoader
jinja = Environment(loader=YamlLoader('templates.yaml'))
username = 'John Doe'
template1 = jinja.get_template('home/welcome')
rendered1 = template1.render(username=username)
print(rendered1) # Welcome, John Doe!
template2 = jinja.get_template('home/goodbye')
rendered2 = template2.render(username=username)
print(rendered2) # Goodbye, John Doe!
```