pkolt / express-nunjucks Goto Github PK
View Code? Open in Web Editor NEWIs the glue for express and nunjucks.
License: MIT License
Is the glue for express and nunjucks.
License: MIT License
Is it possible to retrive the Nunjucks environment? I would like to add custom filters as in
var env = new nunjucks.Environment(); // <-- ERROR with express-nunjucks
env.addFilter('shorten', function(str, count) {
return str.slice(0, count || 5);
});
Thanks
I'm also getting this warning:
[nunjucks] Warning: the "default" filter was used without specifying the type of comparison. 2.0 changed the default behavior from boolean (val ? val : def) to strictly undefined, so you should make sure that doesn't break anything. Be explicit about this to make this warning go away, or wait until 2.1. See http://mozilla.github.io/nunjucks/templating.html#defaultvalue-default-boolean
from that URL:
default(value, default, [boolean])
(aliased as d)
If value is strictly undefined, return default, otherwise value. If boolean is true, any JavaScript falsy value will return default (false, "", etc)
In version 2.0, this filter changed the default behavior of this filter. Previously, it acted as if boolean was true by default, and any falsy value would return default. In 2.0 the default is only an undefined value returns default. You can get the old behavior by passing true to boolean, or just use value or default. 2.0 will show a warning if boolean is not passed, but we will remove this warning in the next version.
When I setup a custom filter and use it inside a Macro it returns errors. If using it outside the macro it works.
const filters = {
shorten: function(str, count) {
return str.slice(0, count || 5);
}
};
const njk = Nunjucks(app, {
autoescape: true,
throwOnUndefined: false,
trimBlocks: false,
lstripBlocks: false,
tags: {},
filters: filters
});
And then while using "shorten"
{{ item.name | shorten }}
# Inside macro
{{ item.name | shorten }}
TypeError: Cannot read property 'slice' of undefined
Any import inside the "conditions" stops the template rendering.
See below, anything is printed.
{% if enabledNewFooter %}
{% include "new_footer.html" %}
{% else %}
{% include "footer.html" %}
{% endif %}
It happens in both blocks (if
/ else
), anything is rendered.
I'm using the following way temporarily:
{% set templateFile = 'a.html' if condition else 'b.html' %}
{% include "directory/" + templateFile %}
While trying to add a custom filter. I getting an error Cannot read property 'SafeString' of undefined
because nunjucks
want defined.
const nunjucksExpress = require('express-nunjucks');
...
nunjucksExpress.ready().then(function (env) {
env.addFilter('inspect', function (data) {
return new nunjucksExpress.nunjucks.runtime.SafeString('<pre><code>' + JSON.stringify(data, undefined, 2) + '</code></pre>');
});
});
I have submitted a PR: #3
No sure if that's the correct way. Happy to discuss.
Is it possible at the moment to change .html extension of templates to .nunjucks?
I'm getting this warning:
[nunjucks] Warning: you passed a boolean as the second argument to FileSystemLoader, but it now takes an options object. See http://mozilla.github.io/nunjucks/api.html#filesystemloader
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.