Search
Try Notion
πŸ“
Jinja2 - Templates
Property
In progress
3 more properties
Jinja is a very useful tool for generating files from templates.
To install it, just use pip:
$ pip install Jinja2
Bash
Delimiters used by Jinja
{% ... %} for Statements
{{ ... }} for Expressions to print to the template output
{# ... #} for Comments not included in the template output
Examples
So far, to generate the System Verilog files I need, I have only needed if/else and for loop statements.
If statement:
<div> {% if True %} yay {% endif %} </div>
HTML
For loop:
<ul> {% for item in seq %} <li>{{ item }}</li> {% endfor %} </ul>
HTML
Whitespace control
When combining if/else nested statements or a for loop, it becomes hard to visualise how the final result will look like. For this, check the whitespace control section here. There is also a good (but long) explanation on how the whitespace control works here. It is also worth using a live Jinja2 Parser here.