A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)
<div class="docs-example">
{% block code_example %}
{% endblock code_example %}
</div>
{% include ‘partials/docs/code-example.html' %}
{% block code_example %}
<ul class="rl-12 rl-grid-4 rl-small-grid-6 rl-x-small-grid-12">
<li class="rl-gutter">
<label for="">Label text</label>
<input type="text" placeholder="Text" />
</li>
<li class="rl-gutter">
<label for="">Label text</label>
<input type="url" disabled="disabled" placeholder="Disabled" />
</li>
<li class="rl-gutter">
<label for="">Label text</label>
<input type="text" readonly="readonly" placeholder="Readonly" />
</li>
</ul>
{% endblock code_example %}
hello, i am facing a problem adding custom filters. I have configured nunjucks as below :
index.js --
const express = require('express');
const nunjucks = require('nunjucks');
const port = 3000;
const app = express();
nunjucks.configure('views', {
autoescape: true,
express: app
})
app.set('view engine', 'html');
const env = new nunjucks.Environment();
env.addFilter('is_undefined', function(obj) {
return typeof obj === 'undefined';
});
for rendering templates, I am using:
res.render('register.html', {errors: errors});
in my template:
{% if errors|is_undefined %}
// do something
{% endif %}
This is the error I am getting: filter not found: is_undefined
I searched for threads on ss.o regarding this issue, some answers indicated I need to use env.render()
instead of res.render()
. But as I do that my page doesn't load anymore. Can someone help me??