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

Copy
{{camelcase "foo bar baz"}};
<!-- results in:  'fooBarBaz' -->

capitalize

Capitalize the first word in a sentence.

Parameters:

  • str {String}

Returns {String}

Example:

Handlebars

Copy
{{capitalize "foo bar baz"}}
<!-- results in:  "Foo bar baz" -->

capitalizeAll

Capitalize all words in a string.

Parameters:

  • str {String}

Returns {String}

Example:

Handlebars

Copy
{{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

Copy
{{chop "_ABC_"}}
<!-- results in:  'ABC' -->

{{chop "-ABC-"}}
<!-- results in:  'ABC' -->

{{chop " ABC "}}
<!-- results in:  'ABC' -->

dashcase

Parameters:

  • string {String}

Returns {String}

Example:

Handlebars

Copy
{{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

Copy
{{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

Copy
{{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

Copy
{{isString "foo"}}
<!-- results in:  'true' -->

lowercase

Lowercase all characters in the given string.

Parameters:

  • str {String}

Returns {String}

Example:

Handlebars

Copy
{{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

Copy
{{occurrences "foo bar foo bar baz" "foo"}}
<!-- results in:  2 -->

pascalcase

PascalCase the characters in string.

Parameters:

  • string {String}

Returns {String}

Example:

Handlebars

Copy
{{pascalcase "foo bar baz"}}
<!-- results in:  'FooBarBaz' -->

pathcase

path/case the characters in string

Parameters:

  • string {String}

  • returns {String}

Example:

Handlebars

Copy
{{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

Copy
{{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

Copy
{{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

Copy
{{reverse "abcde"}}
<!-- results in:  'edcba' -->

sentence

Sentence case the given string

Parameters:

  • str {String}

Returns {String}

Example:

Handlebars

Copy
{{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

Copy
{{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

Copy
{{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

Copy
{{#startsWith "Goodbye" "Hello, world!"}}
  Whoops
{{else}}
  Bro, do you even hello world?
{{/startsWith}}

titleize

  • str {String}

  • returns {String}

Example:

Handlebars

Copy
{{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

Copy
{{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

Copy
{{uppercase "aBcDeF"}}
<!-- results in:  'ABCDEF' -->