Does Jinja2 support template-relative paths e.g. %(here)s/other/template.html
, to include other templates relative to the current template's place in the filesystem?
Jinja2 templates are simple template files that store variables that can change from time to time. When Playbooks are executed, these variables get replaced by actual values defined in Ansible Playbooks. This way, templating offers an efficient and flexible solution to create or alter configuration file with ease.
Jinja, also commonly referred to as "Jinja2" to specify the newest release version, is a Python template engine used to create HTML, XML or other markup formats that are returned to the user via an HTTP response.
I do not believe so. Typically you include or extend other templates by specifying their paths relative to the root of whatever template loader and environment you're using.
So let's say your templates are all in /path/to/templates
and you've set up Jinja like so:
import jinja2 template_dir = '/path/to/templates' loader = jinja2.FileSystemLoader(template_dir) environment = jinja2.Environment(loader=loader)
Now, if you'd like to include /path/to/templates/includes/sidebar.html
in the /path/to/templates/index.html
template, you'd write the following in your index.html
:
{% include 'includes/sidebar.html' %}
and Jinja would figure out how to find it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With