Skip to content

vnyb/jinja2-render

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jinja2-render

Load variables from YAML-formatted files and perform Jinja2 template rendering to the standard output.

Installation

./setup.py install

Usage

jinja2-render <template_name> <data_file1> [<data_file2> ...]

Example

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"
    }
}

Setting template path

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.

Loading extra Jinja2 filters

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

About

Load variables from a YAML-formatted file to render jinja2 template

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages