Articles in this section

#isEmpty helper

Renders the main block when the collection is an empty array/object, the parameter is missing/undefined, or the value is null or undefined; otherwise renders the {{else}} block.

Usage

{{#isEmpty collection}}Block if empty{{else}}Block if not{{/isEmpty}}
  • collection (required): array or object to test

Examples

  1. Check if an array or object is empty

    {{#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
    
  2. Non-empty case

    {{#isEmpty record.items}}No items found{{else}}Items available{{/isEmpty}}
    

    Input:

    { "record": { "items": [1, 2, 3] } }
    

    Output:

    Items available
    

Tip

  • Works with both arrays and objects.

  • For strings, use the #not helper combined with the value to check for emptiness ({{#not record.value}}).

  • Useful for handling optional fields, conditionally rendering messages, or validating data presence.

  • If the input is not an array or plain object (e.g., boolean/number), #isEmpty treats it as empty and renders the main block.