Jinja templates can't import files outside template directory or subdirectory
Problem
I can't include files under templates/include/
directory from a template under template/scripts/
directory.
Actually, the build script sandbox the template in it's own directory.
This limit the includes to things in the same directory:
{%- include "./foo.jinja" %}
or in any subdirectory:
{%- include "./foo/bar.jinja" %}
Proposition
Passing several template directories
The jinja2.FileSystemLoader
support a list of directory where to load templates:
A list of paths can be given. The directories will be searched in order, stopping at the first matching template.
We should at least add the templates/include/
directory.
Anchoring the template search path to the root
Another option could be to root the jinja2.FileSystemLoader
to the top level templates/
directory, making includes working with full path:
{%- include "include/bar.jinja" %}
{%- include "scripts/quuux.jinja" %}
Edited by Daniel Dehennin