Load variables from YAML-formatted files and perform Jinja2 template rendering to the standard output.
./setup.py install
jinja2-render <template_name> <data_file1> [<data_file2> ...]
Template file template.j2
:
{
"user": {
"firstName": "{{ first_name }}",
"lastName": "{{ last_name }}"
}
}
Variable file var.yml
:
---
first_name: Raoul
last_name: Duke
Rendering the template:
jinja2-render template.j2 var.yml
Result:
{
"user": {
"firstName": "Raoul",
"lastName": "Duke"
}
}
The path to Jinja2 template files can be set using the
-t
/--template-path
option:
jinja2-render -t /path/to/templates/ template.j2 var.yml
If omitted, it assumed to be the current working directory.
Extra filters /path/to/extra/filters.py
:
def foo(...):
return ...
def bar(...):
return ...
FILTERS = {
'foo': foo,
'bar': bar,
}
Rendering with extra filters:
jinja2-render -p /path/to/extra -f filters template.j2 var.yml