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

Relative paths are not being resolved #71

Open
eventlistener opened this issue Jul 30, 2019 · 2 comments · May be fixed by #72
Open

Relative paths are not being resolved #71

eventlistener opened this issue Jul 30, 2019 · 2 comments · May be fixed by #72

Comments

@eventlistener
Copy link

eventlistener commented Jul 30, 2019

Template paths are stored in the shared nunjucks.webpackDependencies object as is, without being resolved, which may lead to the corresponding template references being overwritten as next templates are being pre-compiled. As a result, if multiple templates use the same string literal as a relative path in include, import, or extend tags, they all will end up referencing the same template after compilation (which one it will be depends on the order they are imported in the JS file).

Consider the following example:

The same directory structure as in this repo, with include.njk files added in the hero and villain dirs:

test/fixtures/templates/
├── ...
├── hero
|   ├── default.njk
│   └── include.njk
├── ...
└── villain
    ├── default.njk
    └── include.njk

Contents of these include.njk tempates:

{% include './default.njk' %}

(e.g. hero/default.njk and villain/default.njk respectively are meant to be included)

The expected results of rendering hero/include.njk and villain/include.njk would be I am a hero. and I am a villain. respectively, but in fact they are the same (either I am a hero. or I am a villain., depending on which template is imported first).

@eventlistener eventlistener linked a pull request Jul 30, 2019 that will close this issue
@ogonkov
Copy link

ogonkov commented Aug 12, 2019

Nunjucks seems not intend to resolve relative paths mozilla/nunjucks#1214

@eventlistener
Copy link
Author

Weird, there is a way to configure jinja to work with relative paths, as shown in this SO answer. I wonder if there's a nunjucks equivalent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants