Sign inSign up

pinterb/jinja2

By pinterb

•Updated about 9 years ago

Jinja2 is a modern and designer-friendly templating language for Python.

Image
0

10K+

pinterb/jinja2 repository overview

⁠pinterb/jinja2

pinterb/jinja2⁠ is a docker⁠ image that bundles the following:

  • jinja2⁠: A modern and designer-friendly templating language for Python, modelled after Django’s templates.

⁠Usage

As an example, say I want to generate some json from the following jinja2 template:

{
{%- if do_for_fun %}
    "extra_token": "{{ extra_token | default('dummy_value') }}",
{%- endif %}
    "datacenter": "{{ datacenter }}",
    "acl_ttl": "{{ acl_ttl }}"
}

If I run my jinja2 container to render my some.json file:

docker run -i \
    -v ${MY_TEMPLATE_DIR}:/data \
	-e TEMPLATE=some.json.j2 \
	-e "PGID=$(id -g)" -e "PUID=$(id -u)" \
	pinterb/jinja2:0.0.16 datacenter='msp' acl_ttl='30m' > ${PWD}/some.json

The rendered output would be:

{
    "datacenter": "msp",
    "acl_ttl": "30m"
}

Additionally, if you want to write your rendered output to the same directory as your template, just specify the file name by setting the OUT_FILE environment variable:

docker run -i \
    -v ${MY_TEMPLATE_DIR}:/data \
    -v ${MY_OUTPUT_DIR}:/out \
	-e TEMPLATE=some.json.j2 \
	-e OUT_FILE=/out/some.json \
	-e "PGID=$(id -g)" -e "PUID=$(id -u)" \
	pinterb/jinja2:0.0.16 datacenter='msp' acl_ttl='30m'

The key things to remember are:

  • Mount the directory containing your template(s) to the container's /data directory
  • Set the container's environment variable TEMPLATE to the name of your template file
  • The template values are passed in as space delimited name=value pairs
  • Loaded extensions: jinja2.ext.autoescape, jinja2.ext.do, jinja2.ext.loopcontrols, jinja2.ext.with_
  • autoescape is set to True
  • YMMV!!!

⁠Misc. Info

Tag summary

Content type

Image

Digest

Size

22.1 MB

Last updated

about 9 years ago

docker pull pinterb/jinja2