remove¶
The remove filter is a simple yet powerful tool that allows you to remove all occurrences of a specified substring from a string. This filter can be very useful for cleaning up or manipulating text within your templates.
Overview¶
The remove filter is used to return a new string that is a copy of the original string but with all occurrences of the specified substring deleted. This makes it straightforward to eliminate unwanted text from dynamic content.
Syntax¶
Code snippet:
Parameters:
input_string: The string from which you want to remove a part.substring: The substring that you want to remove from theinput_string.
Examples¶
Basic Examples¶
Example 1: Removing a Word
Input:
Output:
Example 2: Removing Special Characters
Input:
Output:
Advanced Examples¶
Example 3: Removing Multiple Occurrences
If the substring appears multiple times in the input string, all occurrences will be removed.
Input:
Output:
Example 4: Removing Whitespaces
Input:
Output:
Use Cases¶
Data Sanitization¶
Often, JSON keys or other content may contain unwanted characters like hyphens or underscores. You can use the remove filter to sanitize those strings efficiently.
Cleaning Up URLs¶
While manipulating URLs, sometimes it's necessary to remove unwanted query parameters or fragments:
Edge Cases and Error Handling¶
- Substring Not Found: If the substring to be removed is not found in the input string, the filter will return the original input string unchanged.
- Empty Substring: If the substring provided is an empty string, the filter will return the original input string.
Additional Tips¶
- Ensure that the substring to be removed is correctly defined, especially when dealing with special characters.
- The
removefilter is not case-sensitive, so "REMOVE" will be treated differently from "remove".
Conclusion¶
The remove filter is a versatile tool in your Experience Builder liquid arsenal. It provides a convenient way to clean up and manipulate strings to fit your presentation requirements. Whether it's for removing specific words, characters, or cleaning up data for further processing, this filter offers a straightforward solution.