capitalize¶
The capitalize filter is designed to modify the capitalization of letters within a string in the Experience Builder templating environment. Specifically, it capitalizes the first letter of the input string and any subsequent letters that follow whitespace, a hyphen, or a period.
Functionality
- Strings: Takes a string as input.
- Capitalization:
- Uppercases the first letter of the string.
- Uppercases any letters that immediately follow a whitespace character (space, tab, newline), a hyphen (-), or a period (.).
- Output: Returns a new string with the modified capitalization.
Syntax
ArgumentsThe capitalize filter does not require any arguments.
Code Samples
Example 1: Capitalizing the First Letter
Output:
Example 2: Capitalizing After PunctuationOutput:
Example 3: Capitalizing After HyphensOutput:
Outliers and Special Cases¶
- Empty Strings: If the input string is empty, the
capitalizefilter returns an empty string. - All Uppercase/Title Case: If the input string is already in all uppercase or title case, the filter might not make any noticeable changes.
- Non-String Input: If the input is not a string, the
capitalizefilter might attempt to convert it to a string or return an error, depending on how Experience Builder handles type conversions.
Key Points¶
- The
capitalizefilter is useful for formatting titles, sentences, or any text where specific capitalization rules need to be applied. - It goes beyond simply capitalizing the first letter by considering punctuation and hyphens.
- For more granular control over capitalization, consider using other string manipulation techniques or custom filters.
- If you only need to capitalize the very first letter of a string, you might achieve this with other built-in string functions or by using string slicing and concatenation.