-
Notifications
You must be signed in to change notification settings - Fork 631
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
Accept relative paths in import/include #349
Conversation
RE: line 142. I've been meaning to accept a PR for this #306, should fix this issue. Thanks for the PR. Does this work with async web loading the templates? |
I just added tests for relative paths: 4869a58 Feel free to let me know if my tests are not following your guidelines. I don't know for async web loading, is there any tests for it? The most of the logic is here: https://github.com/mozilla/nunjucks/pull/349/files#diff-b77b8f7ef4365a2872db79644add92f8R121 One improvement could be to transform this I'm not an english native, so I'm sorry if my messages are not clear. |
Ok, it should be good, I added a |
This is a much requested feature, so thanks for digging in and making a PR! Your approach looks good. I'm not convinced that we need to push the That approach seems fine to me and I would just hardcode that part of the resolution (at least for now). It would still work fine for loading templates over the web, as well as precompiled templates, because when it actually asks for the template it's using the full path. |
Ok, I move the |
I just added an option to the I added a test for this. |
Any news ? :) |
+1 |
Do you want me to rebase the PR or you want to close it? |
Sorry, if you don't mind rebasing, that would be great! |
Done! It passed the tests |
Thanks! I'm pretty slammed at work right now but I'm definitely going to keep going through the PRs this week. |
Accept relative paths in import/include
Neat, because it resolves the path at runtime, it seems to work pretty well. Precompiled templates still work normally, which I thought there might be problem with. Thanks a lot for this! Sorry I didn't get around to looking through it until now. I'll release a new version soon. |
Thanks 🍻 |
Any plans to release this feature in a future version? Thanks! :) |
It's already in multiple released versions. |
Whoops - looks like I was using an npm package that pulled in an outdated version of nunjucks. Sorry for the confusion! |
Does this still work? I can't find a test for <!-- button.njk -->
{% extends ../layout/layout.njk %}
{% block test %}
Hello
{% endblock %} isn't working for me. It says
but the template exists. FileSystemLoader searchPath points to I'm using // filePath === '/Users/tobiasreich/Sites/Templates/Skeleton NJK/src/assets/components/button/button.njk'
env.renderString(str, data, {
path: filePath
}, next) |
It works when I add |
My code seems to fail because |
This PR fixes #228,#326, #243. It simply lets you use
../
and./
in import and include.env.getTemplate
Example:
test.html:
test2.html:
In another matter, I don't think this line https://github.com/mozilla/nunjucks/blob/master/src/environment.js#L142 is a good idea, because if you're using an async loader inside your express application, the app crash if the loader return an error in the callback. The error should be passed to the callback (or throwned if sync): line 163.