String Helpers
This page documents the string-specific handlebars helper expressions available in KX Dashboards templates.
Refer to Apply Templates for details on how to use these expressions.
camelcase
camelCase the characters in the given string
.
Parameters:
-
string
{String}: The string to camelcase.
Returns {String}
Example:
Handlebars
{{camelcase "foo bar baz"}};
<!-- results in: 'fooBarBaz' -->
capitalize
Capitalize the first word in a sentence.
Parameters:
-
str
{String}
Returns {String}
Example:
Handlebars
{{capitalize "foo bar baz"}}
<!-- results in: "Foo bar baz" -->
capitalizeAll
Capitalize all words in a string.
Parameters:
-
str
{String}
Returns {String}
Example:
Handlebars
{{capitalizeAll "foo bar baz"}}
<!-- results in: "Foo Bar Baz" -->
center
Center a string
using non-breaking spaces
Parameters:
-
str
{String} -
spaces
{String}
Returns {String}
chop
Like trim, but removes both extraneous whitespace and non-word characters from the beginning and end of a string
.
Parameters:
-
string
{String}
Returns {String}
Example:
Handlebars
{{chop "_ABC_"}}
<!-- results in: 'ABC' -->
{{chop "-ABC-"}}
<!-- results in: 'ABC' -->
{{chop " ABC "}}
<!-- results in: 'ABC' -->
dashcase
Parameters:
-
string
{String}
Returns {String}
Example:
Handlebars
{{dashcase "a-b-c d_e"}}
<!-- results in: 'a-b-c-d-e' -->
dotcase
dot.case the characters in string.
Parameters:
-
string
{String}
Returns {String}
Example:
Handlebars
{{dotcase "a-b-c d_e"}}
<!-- results in: 'a.b.c.d.e' -->
hyphenate
Replace spaces in a string with hyphens.
Parameters:
-
str
{String}
Returns {String}
Example:
Handlebars
{{hyphenate "foo bar baz qux"}}
<!-- results in: "foo-bar-baz-qux" -->
isString
Return true if value
is a string.
Parameters:
-
value
{String}
Returns {Boolean}
Example:
Handlebars
{{isString "foo"}}
<!-- results in: 'true' -->
lowercase
Lowercase all characters in the given string.
Parameters:
-
str
{String}
Returns {String}
Example:
Handlebars
{{lowercase "Foo BAR baZ"}}
<!-- results in: 'foo bar baz' -->
occurrences
Return the number of occurrences of substring
within the given string
.
Parameters:
-
str
{String} -
substring
{String} -
returns
{Number}: Number of occurrences
Example:
Handlebars
{{occurrences "foo bar foo bar baz" "foo"}}
<!-- results in: 2 -->
pascalcase
PascalCase the characters in string
.
Parameters:
-
string
{String}
Returns {String}
Example:
Handlebars
{{pascalcase "foo bar baz"}}
<!-- results in: 'FooBarBaz' -->
pathcase
path/case the characters in string
Parameters:
-
string
{String} -
returns
{String}
Example:
Handlebars
{{pathcase "a-b-c d_e"}}
<!-- results in: 'a/b/c/d/e' -->
plusify
Replace spaces in the given string
with pluses.
Parameters:
-
str
{String}: The input string
Returns {String}: Input string with spaces replaced by plus signs
Example:
Handlebars
{{plusify "foo bar baz"}}
<!-- results in: 'foo+bar+baz' -->
replace
Replace all occurrences of substring a
with substring b
.
Parameters:
-
str
{String} -
a
{String} -
b
{String}
Returns {String}
Example:
Handlebars
{{replace "a b a b a b" "a" "z"}}
<!-- results in: 'z b z b z b' -->
reverse
Reverse a string.
Parameters:
-
str
{String}
Returns {String}
Example:
Handlebars
{{reverse "abcde"}}
<!-- results in: 'edcba' -->
sentence
Sentence case the given string
Parameters:
-
str
{String}
Returns {String}
Example:
Handlebars
{{sentence "hello world. goodbye world."}}
<!-- results in: 'Hello world. Goodbye world.' -->
snakecase
Snake_case the characters in the given string
.
Parameters:
-
string
{String}
Returns {String}
Example:
Handlebars
{{snakecase "a-b-c d_e"}}
<!-- results in: 'a_b_c_d_e' -->
split
Split string
by the given character
.
Parameters:
-
string
{String}: The string to be split
Returns {String} character
: Default is an empty string.
Example:
Handlebars
{{split "a,b,c" ","}}
<!-- results in: ['a', 'b', 'c'] -->
startsWith
Tests whether a string begins with the given prefix.
Parameters:
-
prefix
{String} -
testString
{String} -
options
{String}
Returns {String}
Example:
Handlebars
{{#startsWith "Goodbye" "Hello, world!"}}
Whoops
{{else}}
Bro, do you even hello world?
{{/startsWith}}
titleize
-
str
{String} -
returns
{String}
Example:
Handlebars
{{titleize "this is title case"}}
<!-- results in: 'This Is Title Case' -->
trim
Removes extraneous whitespace from the beginning and end of a string
.
Parameters:
-
string
{String}: The string to trim.
Returns {String}
Example:
Handlebars
{{trim " ABC "}}
<!-- results in: 'ABC ' -->
uppercase
Uppercase all of the characters in the given string. If used as a block helper, it will uppercase the entire block. This helper does not support inverse blocks.
Parameters:
-
str
{String}: The string to uppercase -
options
{Object}: Handlebars options object
Returns {String}
Example:
Handlebars
{{uppercase "aBcDeF"}}
<!-- results in: 'ABCDEF' -->