The #isEmpty block helper renders one expression when a collection is empty, missing, or null, and an optional {{else}} expression when it contains items. Use it to handle optional fields, validate data presence, or conditionally render messages when no records exist.
Syntax
{{#isEmpty collection}} expr {{else}} expr {{/isEmpty}}
collection -- The array or object to evaluate. Required. If the value is an empty array, empty object, null, or undefined, the helper renders the main block.
Examples
Detect an empty array or object
{{#isEmpty record.arr}}Array is empty{{else}}Has items{{/isEmpty}}
{{#isEmpty record.obj}}Object is empty{{else}}Has keys{{/isEmpty}}
Input:
{
"record": {
"arr": [],
"obj": {}
}
}
Output:
Array is empty Object is empty
Render when the collection has items
{{#isEmpty record.items}}No items found{{else}}Items available{{/isEmpty}}
Input:
{ "record": { "items": [1, 2, 3] } }
Output: Items available
Usage notes
- Works with both arrays and plain objects.
- Renders the main block when
collectionisnull,undefined, or missing -- not just when it's an empty array or object. - If the input is not an array or plain object (for example, a boolean or number), the helper treats it as empty and renders the main block.
- To check whether a string is empty, use
{{#not record.value}}instead --#isEmptyis not designed for string inputs.