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()