Articles in this section

padLeft helper

Adds characters to the beginning of a string or number until it reaches the specified length. By default, it pads with spaces, but you can define any character or string.

Usage

{{padLeft value length "char"}}
  • value (required): string or number to pad

  • length (required): total length of the final string

  • char (optional): the character(s) to pad with. Defaults to a space

Examples

  1. Pad customer ID with zeros

    {{padLeft record.customerId 10 "0"}}
    

    Input:

    { "record": { "customerId": "CUST123" } }
    

    Output:

    000CUST123
    
  2. Pad numeric order ID with spaces (default behavior)

    {{padLeft record.orderId 12}}
    

    Input:

    { "record": { "orderId": "456" } }
    

    Output (spaces on the left):

             456
    

Tip

  • If the input value is already equal to or longer than the target length, the value is returned unchanged.

  • You can use multiple characters as padding (e.g., "AB"). The pattern is repeated and truncated, so the final output length equals the target.

  • If you are padding special character such as &, >, or <, use {{{...}}} to bypass HTML escaping.

  • If length is missing, non-numeric, negative, or zero, the value is returned unchanged.

  • If length is a fractional value such as 5.7, or 5.9, or 5.1, the floor value of the length (this case 5) is taken and applied to the input.

  • Max length supported is 999999. Be cautious when using a very large value for length as it can lead to performance issues

  • Non-string inputs (datatypes such as number or boolean) are converted to strings before processing. Arrays of primitive types (like strings or numbers) are converted into a comma-separated string before processing. If inputs are objects or object arrays, the output will be unusable.