Giter VIP home page Giter VIP logo

express-nunjucks's People

Contributors

andrei-tofan avatar iagomelanias avatar pkolt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

express-nunjucks's Issues

Adding custom filters

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

Warning: "default" filter used without specifying the type of comparison

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.

Can't access custom filter inside macro

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

"include" stops rendering in conditional

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 %}

Expose nunjucks object

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.

Templates extension

Is it possible at the moment to change .html extension of templates to .nunjucks?

FileSystemLoader Boolean warning

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.