Multiple level template inheritance in Jinja2?

One of the best way to achieve multiple level of templating using jinja2 is to use ‘include’ let say you have ‘base_layout.html‘ as your base template <!DOCTYPE html> <title>Base Layout</title> <div> <h1>Base</h1> …. // write your code here {% block body %}{% endblock %} </div> and then you want to have ‘child_layout.html‘ that extends ‘base_layout. … Read more

Remove the empty lines left by Jinja2 variable definitions

There is whitespace control in Jinja2. You might want: {%- set ip = grains[‘ip4_interfaces’][‘eth1’][0] -%} {%- set domain = pillar[‘company_domain’] -%} {%- set version = pillar[‘site_version’] -%} {%- set site_url=”www.” + domain -%} […] As well, the salt configuration file supports jinja_trim_blocks and jinja_lstrip_blocks (jinja_env:trim_blocks, jinja_env:lstrip_blocks, jinja_sls_env:trim_blocks, and jinja_sls_env:lstrip_blocks as of 2018.3).

Getting a request parameter in Jinja2

I’m a bit late with this answer, but the other solutions don’t really account for your use of Flask. The fact that you’re using Flask with Jinja2 makes your situation a bit different from other frameworks. Flask actually makes some global variables available to you in all Jinja2 templates without requiring you to pass them … Read more