Skip to content

size

The 'size' filter is designed to return the number of elements in an array or the number of characters in a string.

Functionality

  • Arrays: If the input value is an array, the size filter returns the number of elements in that array.
  • Strings: If the input value is a string, the size filter returns the number of characters in that string.
  • Other Data Types: For other data types, the behavior of the size filter might vary depending on the specific implementation in Experience Builder. In some cases, it might return the number of properties for an object, or it might not be applicable and return an error or null.

Syntax

    {{ variable | size }} 

Arguments

The size filter does not require any arguments.

Code Samples

Example 1: Size of an Array

    {% assign colors = "red,green,blue" | split: "," %}

    {{ colors | size }} 

Output:

3
Example 2: Size of a String
    {% assign message = "Hello, world!" %}

    {{ message | size }} 

Output:

12

Outliers and Special Cases

  • Empty Arrays/Strings: If the input array or string is empty, the size filter returns 0.
  • Null Values: If the input value is null, the size filter typically returns 0 or null, depending on how Experience Builder handles null values.

Key Points

  • The size filter is a convenient way to determine the length or count of elements in a sequence.
  • It is most commonly used with arrays and strings, but its behavior might differ for other data types.
  • When working with custom objects or complex data structures, it is essential to understand how Experience Builder's size filter interacts with those types to ensure correct results.