nunjucks v0.1.8 Release Notes

Release Date: 2013-02-06 // about 11 years ago
  • πŸš‘ 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()