Skip to content

Instantly share code, notes, and snippets.

@roymanigley
Last active June 3, 2023 23:19
Show Gist options
  • Save roymanigley/2322214ca4ce1e9300671ab013a49487 to your computer and use it in GitHub Desktop.
Save roymanigley/2322214ca4ce1e9300671ab013a49487 to your computer and use it in GitHub Desktop.
Jinja2 - Simple Template Engine

Jinja2 - Simple Template Engine

The Template

{% for name in names %}
{% if name | length == 3 %}
Hello {{ name[1:] | upper }}
{% else %}
Hello {{ name }}
{% endif%}
{% endfor %}

The Template Processing

pip install Jinja2
from jinja2 import Environment, FileSystemLoader

env = Environment(loader=FileSystemLoader(''))
template = env.get_template('./template.txt')
print(template.render(names=["Roy", "John"]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment