Comments (4)
I too was trying to include a file in many different ways and all of them failed. For instance:
{% set standardModal %}
{% include 'standardModalData.html' %}
{% endset %}
Only an include outside any block seems to work.
from express-nunjucks.
It seems that this is a bug of nunjucks.
To solve you can use the synchronous loader templates - nunjucks.FileSystemLoader
.
const express = require('express');
const expressNunjucks = require('express-nunjucks');
const app = express();
app.set('views', __dirname + '/templates');
const njk = expressNunjucks(app, {
loader: nunjucks.FileSystemLoader
});
app.get('/', (req, res) => {
res.render('index');
});
app.listen(3000);
from express-nunjucks.
This also seems to happen while inside loops.
before {% include "partials/hello-world.html" %} after
{% set items = [1, 2, 3] %}
{% for i in items %}
- {{ i }} before {% include "partials/hello-world.html" %} after
{% endfor %}
Output:
before Hello World after
- 1 before
- 2 before
- 3 before
Interestingly, besides using the FileSystemLoader, setting noCache: true
in the configure also works around this issue.
from express-nunjucks.
You can not use includes inside for-loops if you use async loaders. There are two alternative tags called asyncEach and asyncAll that work like the for-loop but allow for async loaders. See the documentation here:
https://mozilla.github.io/nunjucks/templating.html#asynceach
Be aware that macro's don't allow for any async stuff happening inside the macro. So if you use async loaders, includes aren't an option to use inside macro's. A dirty workaround for that is to have the include before the macro call. Example:
<div>
{% include "partials/icons/" + platform + ".svg" %}
{{ icon.icon(platform) }}
</div>
from express-nunjucks.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express-nunjucks.