Search code examples
javascripthtmlnode.jsnunjucks

Resolving nunjucks includes using relative paths?


Is there a way to get the include to understand relative paths with respect to the file that the include statement is in?

Background

I have the following two files:

├── privacy
│   ├── index.html
│   ├── index.md.html

Inside of index.html I have the following include:

{% block content %} 
{% include "./privacy/index.md.html" %}
{% endblock %} </body>

And it works however this does not:

{% block content %} 
{% include "./index.md.html" %}
{% endblock %} </body>

From what I can tell this is because the privacy folder is located in src/test/html/privacy. I have configured nunjucks to resolve files from this directory:

nunjucks.configure(['src/test/html']);


Solution

  • Nunjucks does not allow relative paths. All paths are relative to the configured base directories.

    Reference

    Using relative paths inside an include?