handle¶
The handle filter (also aliased as handleize) transforms an input string into a URL-friendly and human-readable "handle" or "slug." It is particularly useful when generating clean and meaningful identifiers for resources like blog posts, products, or categories.
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
or
(Both syntaxes are equivalent)
Arguments
The handle filter does not require any arguments.
Code Samples
Example 1: Creating a URL Slug
Output: Example 2: Handling Special CharactersOutput:
Example 3: Handling Accents and DiacriticsOutput: (Depending on the underlying normalization rules)
Outliers and Special Cases¶
- Empty Strings: If the input string is empty, the
handlefilter 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.
Key Points¶
- The
handlefilter streamlines the process of creating URL-friendly identifiers (slugs). - It improves the readability of generated handles by replacing special characters with hyphens.
- The filter can be customized by modifying the
Handleizemethod in theMiscFiltersclass if you have specific requirements for handling certain characters. - Consider using the
handlefilter whenever you need to generate clean, concise identifiers for resources within your Experience Builder templates.