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.
{{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).
-
Pad a code with asterisks
{{padRight record.code 6 "*"}}Input:
{ "record": { "code": "XYZ" } }Output:
XYZ***
-
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.