String Filters
String filters transform text values. These are Basker-specific filters in addition to the standard Liquid string filters.
handleize
Section titled “handleize”Converts a string into a URL-safe handle (slug). Useful for creating anchor links, CSS classes, or URL fragments from dynamic content.
Syntax:
{{ string | handleize }}Transformation rules:
- Converts to lowercase
- Replaces spaces and special characters with hyphens
- Removes leading and trailing hyphens
- Preserves accented characters (unicode-safe)
{{ "Hello World" | handleize }}{{ "The Best café in Town!" | handleize }}{{ " Multiple Spaces " | handleize }}{{ "Special @#$ Characters" | handleize }}hello-worldthe-best-café-in-townmultiple-spacesspecial-charactersExample Usage
Section titled “Example Usage”Creating anchor links:
{% for section in page.sections %} <a href="#{{ section.title | handleize }}">{{ section.title }}</a>{% endfor %}
{% for section in page.sections %} <section id="{{ section.title | handleize }}"> <h2>{{ section.title }}</h2> {{ section.content_html }} </section>{% endfor %}Generating CSS classes:
<article class="post post--{{ post.category | handleize }}"> {{ post.content_html }}</article>Building filter URLs:
{% for tag in all_tags %} <a href="/blog?tag={{ tag.title | handleize }}">{{ tag.title }}</a>{% endfor %}handle
Section titled “handle”Alias for handleize. Both filters produce identical output.
{{ "Hello World" | handle }}{# Output: hello-world #}Use whichever reads more naturally in your templates.