Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to extend Nunjucks template #642

LandonSchropp opened this issue Jan 20, 2016 · 2 comments


Copy link

commented Jan 20, 2016

I'm setting up a Gulpfile with gulp-nunjucks, and I'm running into an issue when trying to use extends.


<!doctype html>
<html lang="en">
    {% block content %}{% endblock %}


{% extends './layout.html' %}

{% block content %}
{% endblock %}

Whenever I try to compile my file, I get this error:

Template render error: (unknown path)
Error: template not found: ./layout.html

As far as I can tell, everything should be working. Here's a link to the full repo. Thanks in advance!


This comment has been minimized.

Copy link

commented Jan 21, 2016

Normally with extend (and include) you don't provide paths relative to the current file, but relative to your template root path (configured when you call nunjucks.configure, or alternately when you instantiate e.g. a FileSystemLoader and then pass it to nunjucks.configure. And normally the template paths you pass to extend/include are bare relative paths (e.g. layout.html not ./layout.html, or foo/layout.html not ./foo/layout.html).

I'm not sure how gulp-nunjucks configures nunjucks, and don't have time to investigate right now, but hopefully the above puts you on the right path to figuring out what's going on.

Closing the issue for now; we can re-open if you investigate and are able to confirm a specific bug in nunjucks here.


This comment has been minimized.

Copy link

commented Aug 16, 2018

I had a similar problem, adding a comment here because this seems to be the only proper resource returned by google when looking for this. I tried to use the cli to precompile some files (nunjucks-precompile). I got the same error, which is basically caused if the file can not be found. In precompile.js, line 84 if (pathStats.isFile()) will throw if the file is not found. I suggest this should be checked and a proper error message should be returned.

Which took me an hour to figure out though is this: By default, only files ending with .html or .jinja will be picked up. As my files were named .njk, the script just ignored them all.
The helptext says:

  -i, --include  Include a file or folder which match the regex but would
     otherwise be excluded. You can use this flag multiple times
     [string] [Standard: ["\\.html$","\\.jinja$"]]

For me, it looked optional, only by looking into the code I understood that otherwise it is limited to this default filetype set. I would strongly recommend to add a note about this to the API > precompilation documentation section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.