Install Theme

Your web-browser is very outdated, and as such, this website may not display properly. Please consider upgrading to a modern, faster and more secure browser. Click here to do so.

Nunjucks Changelog

Changelog for
nunjucks, a javascript templating system based on jinja2
Feb 6 '13

v0.1.8 - whitespace controls, unpacking, better errors, and more!

There are lots of cool new features in this release, as well as many critical bug fixes.

Full list of changes:

  • Whitespace control is implemented. Use {%- and -%} to strip whitespace before/after the block.
  • for loops implement Python-style array unpacking. This is a really nice feature which lets you do this:
    {% for x, y, z in [[2, 2, 2], [3, 3, 3]] %}
      --{{ x }} {{ y }} {{ z }}--
    {% endfor %}
    The above would output: --2 2 2----3 3 3--

    You can pass any number of variable names to for and it will destructure each array in the list to the variables.

    This makes the syntax between arrays and objects more consistent. Additionally, it allows us to implement the `dictsort` filter which sorts an object by keys or values. Technically, it returns an array of 2-value arrays and the unpacking takes care of it. Example:
    {% for k, v in { b: 2, a: 1 } %}
      --{{ k }}: {{ v }}--
    {% endfor %}
    Output: --b: 2----a: 1--(note: the order could actually be anything because it uses javascript’s `for k in obj` syntax to iterate, and ordering depends on the js implementation)
    {% for k, v in { b: 2, a: 1} | dictsort %}
      --{{ k }}: {{ v }}--
    {% endfor %}
    Output: --a: 1----b: 2--

    The above output will always be ordered that way. See the documentation for more details.

    Thanks to novocaine for this!
  • Much better error handling with at runtime (shows template/line/col information for attempting to call undefined values, etc)
  • Fixed a regression which broke the {% raw %} block
  • Fix some edge cases with variable lookups
  • Fix a regression with loading precompiled templates
  • Tweaks to allow usage with YUICompressor
  • Use the same error handling as normal when precompiling (shows proper errors)
  • Fix template loading on Windows machines
  • Fix int/float filters
  • Fix regression with super()
Dec 12 '12

v0.1.7 - helpful errors, many bug fixes

The biggest change in v0.1.7 comes from devoidfury (thanks!) which implements consistent and helpful error messages. The errors are still simply raw text, and not pretty HTML, but they at least contain all the necessary information to track down an error, such as template names, line and column numbers, and the inheritance stack. So if an error happens in a child template, it will print out all the templates that it inherits. In the future, we will most likely display the actual line causing an error.

Full list of changes:

  • Consistent and helpful error messages
  • Expressions are more consistent now. Previously, there were several places that wouldn’t accept an arbitrary expression that  should. For example, you can now do {% include templateNames['foo'] %}, whereas previously you could only give it a simply variable name.
  • app.locals is fixed with express 2.5
  • Method calls on objects now have correct scope for this. Version 0.1.6 broke this and this was referencing the global scope.
  • A check was added to enforce loading of templates within the correct path. Previously you could load a file outside of the template with something like ../../crazyPrivateFile.txt

You can view all the code changes here. Please file an issue if something breaks!

Nov 13 '12

v0.1.6 - undefined handling, bugfixes

This is mostly a bugfix release, but there are a few small tweaks based on feedback:

  • In some cases, backslashes in the template would not appear in the output. This has been fixed.
  • An error is thrown if a filter is not found
  • Old versions of express are now supported (2.5.11 was tested)
  • References on undefined objects are now suppressed. For example, {{ foo }}, {{ foo.bar }}, {{ foo.bar.baz }} all output nothing if foo is undefined. Previously only the first form would be suppressed, and a cryptic error thrown for the latter 2 references. Note: I believe this is a departure from jinja, which throws errors when referencing undefined objects. I feel that this is a good and non-breaking addition though. (thanks to devoidfury)
  • A bug in set where you couldn’t not reference other variables is fixed (thanks chriso and panta)
  • Other various small bugfixes

You can view all the code changes here. As always, file an issue if something breaks!

Oct 11 '12

v0.1.5 - macros, keyword arguments, bugfixes

v0.1.5 has been pushed to npm, and it’s a big one. Please file any issues you find, and I’ll fix them as soon as possible!

  • The node data structure has been completely refactored to reduce redundancy and make it easier to add more types in the future.
  • Thanks to Brent Hagany, macros now have been implemented. They should act exactly the way jinja2 macros do.
  • A calling convention which implements keyword arguments now exists. All keyword args are converted into a hash and passed as the last argument. Macros needed this to implement keyword/default arguments.
  • Function and filter calls apply the new keyword argument calling convention
  • The “set” block now appropriately only sets a variable for the current scope.
  • Many other bugfixes.

I’m watching this release carefully because of the large amount of code that has changed, so please file an issue if you have a problem with it.