What is a Jinja2 template?
Template engine
Jinja2 is a template engine for the Python programming language. A Jinja2 template is a structured file containing template tag blocks, or variables, and instructions for how to replace the variables with data. The template engine uses a Python script to read a YAML data file, insert the data into the template tag blocks, and generate the file. For example, Jinja2 templates can be used to convert a data set to a more reader-friendly format such as an HTML document.
Jinja2 templates can be created in NSP, imported, or installed using Artifacts; see How do I install an artifact bundle?.
See the Workflows tutorial on the Network Developer Portal for details about working with Jinja2 templates.
Sample template
The Jinja2 template below is a simple template that creates an HTML page.
name: myJinja
tags:
- a
- b
description: Sample Jinja2 Template
template: |
<!doctype html>
<title>{% block title %}{% endblock %}</title>
<ul>
{% for user in users %}
<li><a href="{{ user.url }}">{{ user.username }}</a></li>
{% endfor %}
</ul>
<p>
Refer to https://jinja.palletsprojects.com/en/2.10.x/api/
</p>