String Helpers
String manipulation and formatting functions that transform text values and return processed strings.
| Helper | Purpose | Parameters | Returns |
|---|---|---|---|
format | Converts a value to a string with optional formatting | value, format? | string |
upperCase | Converts a string to uppercase | text | string |
lowerCase | Converts a string to lowercase | text | string |
kebabCase | Converts a string to kebab-case | text | string |
snakeCase | Converts a string to snake_case | text | string |
titleCase | Converts a string to title case | text | string |
split | Splits a string by a separator | input, separator | string[] |
concat | Concatenates string representation of some values into a single string | ...values | string |
firstNonBlank | Returns the first non-blank value | ...values | string? |
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:
value(any) - The object to convert to stringformat(string, optional) - Format string for formattable objects
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:
string(string) - The string to splitdelimiter(string) - The delimiter to split by
Returns: Array of string parts
Examples:
<ul>
{{#each (split "apple,banana,cherry" ",")}}
<li>{{this}}</li>
{{/each}}
</ul>
{{#each (split model.name ".")}}
{{this}}{{#unless @last}}•{{/unless}}
{{/each}}
concat
Concatenates string representation of some values into a single string.
Syntax:
{{#concat values}}
{{#concat value1 value2 value3 ...}}
Parameters:
values(array) - Collection of values to concatenatevalue1, value2, value3 ...(any) - values to concatenate
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:
string(string) - The string to convert
Returns: Uppercase string
Examples:
{{#upperCase "hello world"}} {{!-- "HELLO WORLD" --}}
{{#upperCase model.name}} {{!-- "MYCLASS" --}}
lowerCase
Converts a string to lowercase.
Syntax:
{{#lowerCase string}}
Parameters:
string(string) - The string to convert
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:
string(string) - The string to convert
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:
string(string) - The string to convert
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:
string(string) - The string to convert
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:
value1, value2, value3 ...(any) - Values to check in order
Returns: First argument that is not empty, whitespace, or null, or null if all are blank.
Examples:
{{#firstNonBlank model.name "Untitled"}}
