Inline `if` should return `undefined` if there's no `else`
Author: romaricpascalCreated Jul 14, 2025Updated Jul 14, 2025
Currently, inline if expressions are compiled to return an empty string in the absence of an else.
Jinja's templating documentation specifies that an inline if expression should return an Undefined object.
For parity with Jinja, seems Nunjucks inline ifs should also evaluate to undefined in the absence of an else. Both '' and undefined are falsy, but some code may require to differenciate between undefined (no value was given) and '' (an empty string was given). Such code gets easily broken if called with <SOMETHING> if <CONDITION> as you'd expect undefined but get ''.
Source: mozilla/nunjucks