Articles in this section

padRight helper

Adds characters to the end 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

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

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

  • char (optional): The character(s) to pad with (defaults to a space).

Examples

  1. Pad a code with asterisks

    {{padRight record.code 6 "*"}}
    

    Input:

    { "record": { "code": "XYZ" } }
    

    Output:

    XYZ***
    
  2. Pad an order ID with spaces (default behavior)

    {{padRight record.orderId 8}}
    

    Input:

    { "record": { "orderId": "123" } }
    

    Output (spaces on the right):

    123     
    

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.

  • By default, Handlebars HTML-escapes the result. If you need raw output (for strings containing <, >, &, etc.), use {{{…}}}

  • 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.

  • Non-string datatype inputs (like 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.