hanleize¶
The handleize filter (also known as handle) transforms an input string into a URL-friendly and human-readable "handle" or "slug." It achieves this by converting the string to lowercase, replacing spaces and special characters with hyphens, and removing any invalid characters.
Functionality
-
Strings: Takes a string as input.
-
Normalization:
- Converts all letters to lowercase.
- Replaces spaces, punctuation, and other special characters with hyphens.
- Removes any remaining invalid characters that are not letters, numbers, or hyphens.
- Ensures consecutive capital letters are separated by a hyphen.
- Output: Returns a new string that is suitable for use in URLs or as a human-readable identifier.
Syntax
orArguments
Code SamplesExample 1: Creating a URL Slug
Output: Example 2: Handling Special CharactersOutput:
Example 3: Handling Consecutive Capital Letters Output:Outliers and Special Cases¶
- Empty Strings: If the input string is empty, the
handleizefilter returns an empty string. - Non-String Input: If the input is not a string, the filter might attempt to convert it to a string or return an error, depending on how Experience Builder handles type conversions.
- Customizable Rules: You can extend or customize the rules for how the
handleizefilter transforms characters by modifying its implementation in theMiscFiltersclass.
Key Points¶
- The
handleizefilter is essential for generating clean, URL-friendly slugs for blog posts, product pages, or any content that needs a unique identifier. - It enhances readability by replacing special characters with hyphens.
- It ensures that the output string is valid for use in URLs.
- Consider customizing the filter's rules if you have specific requirements for handling certain characters or patterns.