String Helpers

String manipulation and formatting functions that transform text values and return processed strings.

HelperPurposeParametersReturns
formatConverts a value to a string with optional formattingvalue, format?string
upperCaseConverts a string to uppercasetextstring
lowerCaseConverts a string to lowercasetextstring
kebabCaseConverts a string to kebab-casetextstring
snakeCaseConverts a string to snake_casetextstring
titleCaseConverts a string to title casetextstring
splitSplits a string by a separatorinput, separatorstring[]
concatConcatenates string representation of some values into a single string...valuesstring
firstNonBlankReturns the first non-blank value...valuesstring?

format

Returns the string representation of an object with optional formatting.

The format parameter can be used to specify a format string for formattable objects like numbers and dates.

The culture used for formatting is the invariant culture.

Syntax:

{{#format value}}
{{#format value format}}

Parameters:

Returns: String representation of the object

Examples:

{{#format 42}}                    {{!-- "42" --}}
{{#format 3.14159 "F2"}}          {{!-- "3.14" --}}
{{#format true}}                  {{!-- "True" --}}
{{#format null}}                  {{!-- "" --}}
{{#format topic}}                 {{!-- String value of topic, which is its title --}}

split

Splits a string by a specified delimiter.

Syntax:

{{#split string delimiter}}

Parameters:

Returns: Array of string parts

Examples:

<ul>
  {{#each (split "apple,banana,cherry" ",")}}
  <li>{{this}}</li>
  {{/each}}
</ul>

{{#each (split model.name ".")}}
  {{this}}{{#unless @last}}&bull;{{/unless}}
{{/each}}

concat

Concatenates string representation of some values into a single string.

Syntax:

{{#concat values}}
{{#concat value1 value2 value3 ...}}

Parameters:

Returns: Concatenated string

Examples:

{{#concat "Hello" " " "World"}}             {{!-- "Hello World" --}}
{{#concat model.namespace "." model.name}}  {{!-- "MyApp.MyClass" --}}
{{#concat ["a", "b"]}}                      {{!-- "ab" --}}

upperCase

Converts a string to uppercase.

Syntax:

{{#upperCase string}}

Parameters:

Returns: Uppercase string

Examples:

{{#upperCase "hello world"}}           {{!-- "HELLO WORLD" --}}
{{#upperCase model.name}}              {{!-- "MYCLASS" --}}

lowerCase

Converts a string to lowercase.

Syntax:

{{#lowerCase string}}

Parameters:

Returns: Lowercase string

Examples:

{{#lowerCase "HELLO WORLD"}}           {{!-- "hello world" --}}
{{#lowerCase model.name}}              {{!-- "myclass" --}}

kebabCase

Converts a string to kebab-case (lowercase with hyphens).

Syntax:

{{#kebabCase string}}

Parameters:

Returns: Kebab-case string

Examples:

{{#kebabCase "Hello World"}}           {{!-- "hello-world" --}}
{{#kebabCase "XMLParser"}}             {{!-- "xml-parser" --}}
{{#kebabCase model.name}}              {{!-- "my-class" --}}

snakeCase

Converts a string to snake_case (lowercase with underscores).

Syntax:

{{#snakeCase string}}

Parameters:

Returns: Snake_case string

Examples:

{{#snakeCase "Hello World"}}           {{!-- "hello_world" --}}
{{#snakeCase "XMLParser"}}             {{!-- "xml_parser" --}}
{{#snakeCase model.name}}              {{!-- "my_class" --}}

titleCase

Converts a string to title case (first letter of each word capitalized).

Syntax:

{{#titleCase string}}

Parameters:

Returns: Title case string

Examples:

{{#titleCase "hello world"}}           {{!-- "Hello World" --}}

firstNonBlank

Returns the string representation of the first argument that is not empty, whitespace, or null.

Syntax:

{{#firstNonBlank values}}
{{#firstNonBlank value1 value2 value3 ...}}

Parameters:

Returns: First argument that is not empty, whitespace, or null, or null if all are blank.

Examples:

{{#firstNonBlank model.name "Untitled"}}