prepend¶
The prepend filter is designed to concatenate a specified string to the beginning of the input string.
Functionality
- Strings: Takes a string as input.
- Prefix: Requires a string argument to add to the beginning.
- Output: Returns a new string with the prefix string added at the start.
Syntax
Arguments- string_to_prepend: The string that you want to add to the beginning of the
input_string.
Code Samples
Example 1: Prepending a Title
Output:
Example 2: Prepending a Prefix Output: Example 3: Prepending an Empty String Output:Outliers and Special Cases¶
- Empty Input String: If the input string is empty, the prepended string becomes the entire output.
- Non-String Input: If the input is not a string, the
prependfilter might attempt to convert it to a string or return an error, depending on how Experience Builder handles type conversions. - Multiple Prepends: You can chain multiple
prependfilters to add multiple strings to the beginning.
Key Points¶
- The
prependfilter is a simple yet powerful tool for dynamically constructing strings in templates. - It can be used for adding titles, prefixes, or any other string that needs to be placed at the start of another string.
- If you want to add a string to the end, use the
appendfilter instead. - Consider using the
formatfilter or string interpolation for more complex string formatting tasks.