php-handlebars icon indicating copy to clipboard operation
php-handlebars copied to clipboard

`if` helper does not consider `null` as a false value when used with path expression

Open Jackardios opened this issue 11 months ago • 0 comments

if helper does not consider null as a falsy value when used with path expression:

$handlebars->render('{{#if nested.someNullValue}}should not be shown{{/if}}', ['nested' => ['someNullValue' => null]])
// rendered as "should not be shown"

$handlebars->render('{{#if someNullValue}}should not be shown{{/if}}', ['someNullValue' => null])
// rendered as ""

This only happens with path expression and this behavior is different from how this template is rendered in handlebarsjs: https://handlebarsjs.com/playground.html#format=1&currentExample=%7B%22template%22%3A%22%7B%7B%23if%20nested.someNullValue%7D%7Dshould%20not%20be%20shown%7B%7B%2Fif%7D%7D%22%2C%22partials%22%3A%5B%5D%2C%22input%22%3A%22%7B%5Cn%20%20nested%3A%20%7B%20someNullValue%3A%20null%20%7D%2C%5Cn%7D%5Cn%22%2C%22output%22%3A%22%22%2C%22preparationScript%22%3A%22%22%2C%22handlebarsVersion%22%3A%224.7.8%22%7D

Jackardios avatar Apr 23 '25 02:04 Jackardios