Strings
abbreviate
Truncates text with an ellipsis when it exceeds the width.
Data:
{
"title": "Handlebars rocks"
}
Output:
Handlebars...
capitalize
Capitalizes every whitespace-separated word.
Data:
{
"title": "my first post"
}
Output:
My First Post
Fully normalize capitalization:
Data:
{
"title": "mY FIRST pOSt"
}
Output:
My First Post
capitalizeFirst
Capitalizes the first character.
Data:
{
"title": "handlebars.java"
}
Output:
Handlebars.java
center
Centers text in a field of a given width.
Data:
{
"name": "Bob"
}
Output conceptually:
' Bob '
Use custom padding:
concat
Returns the concatenation of the arguments.
Usage:
Null values will be cast to empty strings. See the similar XPath 1.0 function.
cut
Removes all occurrences of a substring. The default substring is a space.
Data:
{
"text": "String with spaces"
}
Output:
Stringwithspaces
Custom cut string:
defaultIfEmpty
Returns a default value when the input is empty.
Data:
{
"nickname": ""
}
Output:
Anonymous
join
Joins iterable, iterator, array, or multiple values.
Data:
{
"tags": [
"java",
"handlebars",
"template"
]
}
Output:
java, handlebars, template
With prefix/suffix:
Output:
[java, handlebars, template]
Join positional values:
Output:
a / b / c
ljust
Left-aligns text by padding on the right.
Data:
{
"name": "Bob"
}
Output conceptually:
'Bob '
lower
Converts text to lowercase.
Data:
{
"title": "Still MAD At Yoko"
}
Output:
still mad at yoko
normalizeSpace
Returns the argument string with the leading, trailing, and repeating white spaces stripped.
See the similar XPath 1.0 function.
numberFormat
Formats Java Number values.
Data:
{
"price": 1234.5
}
Output:
1,234.50
Predefined styles:
Fraction options:
Disable grouping:
rjust
Right-aligns text by padding on the left.
Data:
{
"name": "Bob"
}
Output conceptually:
' Bob'
replace
Replaces all literal occurrences of a target substring.
Data:
{
"text": "Handlebars ..."
}
Output:
Handlebars rocks
replaceAll
Replaces each substring of the input string applying the regular expression in the first parameter and using th second parameter as the replacement pattern.
Usage:
If the value is Handlebars/png, the output will be Handlebars (ext=png).
To set global flags, you can prefix the expression with (?i) or (?m), (?im). The evaluation is always global.
This uses the Java semantics for regex.
slugify
Converts text to a simple lowercase slug. This implementation keeps letters and converts whitespace to hyphens.
Data:
{
"title": "Joel is a slug"
}
Output:
joel-is-a-slug
string
Converts an object to a string.
See the similar XPath 1.0 function.
Note: Different from XPath the string representation of an array or of an object is not the concatenation of all plain text values. Instead, it produces a string representation of the complete object tree as defined in the Java programming language.
stringFormat
Uses Java String.format.
Data:
{
"name": "Handlebars.java"
}
Output:
Hello Handlebars.java
Number formatting example:
Data:
{
"price": 123.4567
}
Output:
123.46
stringLength
Returns the number of characters in the string.
If an argument is not of type string, it is first converted to a string and then evaluated.
See the similar XPath 1.0 function.
stripTags
Removes HTML/XML tags.
Data:
{
"html": "<p>Hello <strong>world</strong></p>"
}
Output:
Hello world
substring
Returns a substring by start and optional end index.
Data:
{
"value": "Handlebars.java"
}
Output:
java
With end index:
Output:
Handlebars
substringAfter
Returns the substring of the first argument string that follows the first occurrence of the second argument string in the first argument string. See the similar XPath 1.0 function.
substringBefore
Returns the substring of the first argument string that precedes the first occurrence of the second argument string in the first argument string. See the similar XPath 1.0 function.
translate
Returns the first argument string with occurrences of characters in the second argument string replaced by the character at the corresponding position in the third argument string.
This function provides a mapping of characters on the first argument. The second and third arguments describe the scheme of the mapping.
If there is a character in the second argument string with no character at a corresponding position in the third argument string (because the second argument string is longer than the third argument string), occurrences of that character in the first argument string are removed. If a character occurs more than once in the second argument string, the first occurrence determines the replacement character. If the third argument string is longer than the second argument string, excess characters are ignored.
If an argument is not of type string, it is first converted to a string and then evaluated.
See the similar XPath 1.0 function.
unescapeHtml
Returns a string with all HTML escaped characters in raw form.
Data:
{
"title": "<Français>"
}
Output:
<Français>
upper
Converts text to uppercase.
Data:
{
"title": "Hello"
}
Output:
HELLO
wordWrap
Wraps text at the requested width.
Data:
{
"text": "Joel is a slug"
}
Output conceptually:
Joel
is a
slug
yesno
Maps boolean/null values to strings.
Data:
{
"published": true
}
Output:
yes
Custom labels:
For null, the helper returns the maybe value.