String functions
capitalizeFirst
: Capitalizes the first character of the value.
If the value is "kestra is cool !", the output will be "Kestra is cool !".
{{capitalizeFirst value}}
center
: Centers the value in a field of a given width.
If the value is "Handlebars.java", the output will be " Handlebars.java ".
{{ center value size=19 [pad="char"] }}
Arguments:
size
pad
cut
: Removes all values of arg from the given string.
If the value is "String with spaces", the output will be "Stringwithspaces".
{{cut value [" "]}}
defaultIfEmpty
: Default if empty
If the value evaluates to False, it will use the given default. Otherwise, it uses the value. If value is "" (an empty string), the output will be nothing.
{{defaultIfEmpty value ["nothing"] }}
join
: Join string
Joins an array, iterator or an iterable with a string.
{{join value join [prefix=""] [suffix=""]}}
Arguments:
join
prefix
suffix
If value is the list 'a', 'b', 'c', the output will be the string "a // b // c".
{{join value " // " [prefix=""] [suffix=""]}}
Join the "a", "b", "c", the output will be the string "a // b // c".
{{join "a" "b" "c" " // " [prefix=""] [suffix=""]}}
ljust
: Left-aligns the value in a field of a given width.
If the value is Handlebars.java, the output will be "Handlebars.java ".
{{ljust value 20 [pad=" "] }}
Arguments:
field size
rjust
: Right-aligns the value in a field of a given width.
If the value is Handlebars.java, the output will be " Handlebars.java".
{{rjust value 20 [pad=" "] }}
Arguments:
field size
pad
substring
Substring
Returns a new CharSequence
that is a subsequence of this sequence.
The subsequence starts with the char
value at the specified index and
ends with the char
value at nd - 1*
{{substring value start end }}
Arguments:
start offset
end offset
For example:
If the value is Handlebars.java, the output will be "java".
{{substring value 11 }}
If the value is Handlebars.java, the output will be "Handlebars".
{{substring value 0 10 }}
lower
: Converts a string into all lowercase.
If the value is 'Still MAD At Yoko', the output will be 'still mad at yoko'.
{{lower value}}
upper
Converts a string into all uppercase.
If the value is 'Hello', the output will be 'HELLO'.
{{upper value}}
slugify
Converts to lowercase
This removes non-word characters (alphanumerics and underscores) and converts spaces to hyphens. It also strips leading and trailing whitespace. If the value is "Joel is a slug", the output will be "joel-is-a-slug".
{{slugify value}}
stringFormat
: Formats the variable
According to the argument, a string formatting specifier. If the value is "Hello %s" "handlebars.java", the output will be "Hello handlebars.java".
{{stringFormat string param0 param1 ... paramN}}
Arguments:
format
paramN
stripTags
: Strips all XHTML tags.
{{stripTags value}}
capitalize
: Capitalizes all the whitespace separated words in a String.
If the value is "my first post", the output will be "My First Post".
{{ capitalize value [fully=false]}}
Arguments:
fully
abbreviate
: Truncates a string
The string will be truncated if it is longer than the specified number of characters. Truncated strings will end with a translatable ellipsis sequence ("..."). If value is "Handlebars rocks", the output will be "Handlebars...".
{{abbreviate value 13 }}
Arguments:
- Number of characters to truncate to
wordWrap
: Wraps words
This wraps the sentence at a specified line length. If value is Joel is a slug, the output would be: Joel\nis a\nslug
{{ wordWrap value 5 }}
Arguments:
- the number of characters at which to wrap the text
replace
Replaces
Each substring of this string that matches the literal target sequence with the specified literal replacement sequence. If value is "Handlebars ...", the output will be "Handlebars rocks".
{{ replace value "..." "rocks" }}
yesno
: Boolean to yes / no
For true, false and (optionally) null, to the strings "yes", "no", "maybe".
Arguments:
yes
no
maybe
{{yesno value [yes="yes"] [no="no"] maybe=["maybe"] }}