Formatting and Cleaning Text
String filters prepare merchant-entered content for safe, consistent display. Product descriptions, blog excerpts, and SEO meta text all rely on string filters.
- upcase / downcase / capitalize — change letter casing
- strip / lstrip / rstrip — remove whitespace from both ends or one side
- split: 'delimiter' — break a string into an array
- join: ', ' — combine array items into a string
- replace: 'old', 'new' — substitute text (first occurrence per call)
- remove: 'text' — delete all occurrences of a substring
- truncate: N / truncatewords: N — shorten long text
- escape — convert < > & to HTML entities (critical in attributes)
- strip_html — remove all HTML tags from rich text
Common string transformations
{{ ' hello world ' | strip | capitalize }}
{# Output: Hello world #}
{{ product.tags | join: ' · ' }}
{# Output: web · programming · sale #}
{{ article.title | truncate: 50 }}
{# Output: Long article title that gets cut… #}Always use | escape when inserting user or merchant content into HTML attributes: alt="{{ product.title | escape }}". Without escape, a title containing a quote character breaks the attribute and can cause XSS.
Note: strip_html is destructive — it removes formatting. Use truncatewords on plain text excerpts, not full product descriptions meant to render HTML.