Skip to content

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

    {{ input_string | handleize }} 
or

    {{ input_string | handle }} 

Arguments

The `handleize` filter does not require any arguments.
Code Samples

Example 1: Creating a URL Slug

    {% assign title = "This is a Blog Post Title" %}

    {{ title | handleize }}
Output:
this-is-a-blog-post-title
Example 2: Handling Special Characters

    {% assign product_name = "Awesome Product! (with special chars)" %}

    {{ product_name | handleize }}

Output:

awesome-product-with-special-chars
Example 3: Handling Consecutive Capital Letters

    {% assign acronym = "NASAIsCool" %}

    {{ acronym | handleize }}
Output:
nasa-is-cool

Outliers and Special Cases

  • Empty Strings: If the input string is empty, the handleize filter 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 handleize filter transforms characters by modifying its implementation in the MiscFilters class.

Key Points

  • The handleize filter 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.