Filters¶
Filters transform data in expressions using Liquid — a templating language standard. Each filter takes an input value, applies a transformation, and outputs a new value.
Filters are chained in expressions. Example: posts → first → title → upcase uses three filters (first, title is a navigation property, upcase is a filter).
This page documents every available filter with its input/output type, options, and examples.
String filters¶
These filters work on text values.
strip_html¶
Removes all HTML tags from a string.
Input: String (e.g., <p>Hello <strong>world</strong></p>)
Output: String (e.g., Hello world)
Options: None
Example: post_content → strip_html removes HTML from rich text fields
append¶
Adds text to the end of a string.
Input: String
Output: String
Options: value (text to append)
Example: post_title → append(" - Blog") changes "My Post" to "My Post - Blog"
prepend¶
Adds text to the beginning of a string.
Input: String
Output: String
Options: value (text to prepend)
Example: post_title → prepend("New: ") changes "My Post" to "New: My Post"
upcase¶
Converts a string to uppercase.
Input: String
Output: String
Options: None
Example: post_title → upcase changes "hello" to "HELLO"
downcase¶
Converts a string to lowercase.
Input: String
Output: String
Options: None
Example: post_title → downcase changes "Hello" to "hello"
capitalize¶
Capitalizes the first character and lowercases the rest.
Input: String
Output: String
Options: None
Example: "hello WORLD" → capitalize becomes "Hello world"
replace¶
Replaces all occurrences of a substring with another.
Input: String
Output: String
Options: search (text to find), replace (replacement text)
Example: "Hello World" → replace("World", "Silex") becomes "Hello Silex"
replace_first¶
Replaces only the first occurrence of a substring.
Input: String
Output: String
Options: search, replace
Example: "aaa" → replace_first("a", "b") becomes "baa"
replace_last¶
Replaces only the last occurrence of a substring.
Input: String
Output: String
Options: search, replace
Example: "aaa" → replace_last("a", "b") becomes "aab"
remove¶
Removes all occurrences of a substring (equivalent to replace with empty string).
Input: String
Output: String
Options: search (text to remove)
Example: "Hello World" → remove("World") becomes "Hello "
remove_first¶
Removes only the first occurrence of a substring.
Input: String
Output: String
Options: search
Example: "aaa" → remove_first("a") becomes "aa"
remove_last¶
Removes only the last occurrence of a substring.
Input: String
Output: String
Options: search
Example: "aaa" → remove_last("a") becomes "aa"
truncate¶
Shortens a string to a maximum length.
Input: String
Output: String
Options: length (max characters, default 50)
Example: "This is a very long sentence" → truncate(10) becomes "This is a "
truncatewords¶
Shortens a string to a maximum number of words.
Input: String
Output: String
Options: length (max words, default 15)
Example: "This is a very long sentence" → truncatewords(3) becomes "This is a"
escape¶
Escapes double quotes in a string.
Input: String
Output: String
Options: None
Example: post_title → escape converts "Hello" to \"Hello\"
escape_once¶
Escapes double quotes (once, even if already escaped).
Input: String Output: String Options: None
newline_to_br¶
Converts newlines (\n) to HTML break tags (<br />).
Input: String
Output: String
Options: None
Example: "Line 1\nLine 2" → newline_to_br becomes "Line 1<br />Line 2"
strip_newlines¶
Removes all newlines from a string.
Input: String
Output: String
Options: None
Example: "Line 1\nLine 2" → strip_newlines becomes "Line 1Line 2"
Array filters¶
These filters work on lists.
where¶
Filters a list to items matching a condition.
Input: List of objects
Output: List of objects
Options: key (field name), value (value to match)
Example: posts → where(category = "news") returns only posts in the news category
find¶
Returns the first item in a list matching a condition.
Input: List of objects
Output: One object
Options: key, value
Example: posts → find(id = 5) returns the post with id 5
first¶
Returns the first item in a list.
Input: List
Output: One item
Options: None
Example: posts → first returns the first post
last¶
Returns the last item in a list.
Input: List
Output: One item
Options: None
Example: posts → last returns the last post
join¶
Joins a list of strings into a single string with a separator.
Input: List of strings
Output: String
Options: separator (what to put between items, default ",")
Example: tags → join(", ") joins tags with commas: "tag1, tag2, tag3"
split¶
Splits a string into a list using a separator.
Input: String
Output: List of strings
Options: separator (what to split on, default ",")
Example: "tag1, tag2, tag3" → split(", ") becomes a list of three tags
map¶
Extracts a specific field from each item in a list.
Input: List of objects
Output: List of values
Options: key (field name to extract)
Example: posts → map(title) extracts all post titles into a list
reverse¶
Reverses the order of a list.
Input: List
Output: List (reversed)
Options: None
Example: posts → reverse returns posts in reverse order
size¶
Returns the number of items in a list (or characters in a string).
Input: List or String
Output: Number
Options: None
Example: posts → size returns the count of posts
slice¶
Extracts a portion of a list by start and end index.
Input: List
Output: List
Options: start (start index), end (end index)
Example: posts → slice(0, 3) returns the first 3 items
sort¶
Sorts a list of objects by a field name (alphabetically or numerically).
Input: List of objects
Output: List (sorted)
Options: key (field to sort by)
Example: posts → sort(title) sorts posts alphabetically by title
compact¶
Removes empty/null/false items from a list.
Input: List
Output: List (without empty values)
Options: None
Example: authors → compact removes null author entries
sample¶
Picks one or more random items from a list.
Input: List
Output: List or single item
Options: count (number of items to pick, default 1)
Example: posts → sample(3) returns 3 random posts
Math filters¶
These filters work on numbers.
plus¶
Adds a number to another number.
Input: Number
Output: Number
Options: value (number to add)
Example: price → plus(10) adds $10 to the price
minus¶
Subtracts a number.
Input: Number
Output: Number
Options: value (number to subtract)
Example: price → minus(5) subtracts $5 from the price
times¶
Multiplies a number.
Input: Number
Output: Number
Options: value (number to multiply by)
Example: quantity → times(2) doubles the quantity
divided_by¶
Divides a number.
Input: Number
Output: Number
Options: value (number to divide by)
Example: total → divided_by(2) divides the total by 2
modulo¶
Returns the remainder after division.
Input: Number
Output: Number
Options: value (divisor)
Example: count → modulo(2) returns 0 if even, 1 if odd
ceil¶
Rounds up to the nearest integer.
Input: Number
Output: Integer
Options: None
Example: 3.2 → ceil becomes 4
floor¶
Rounds down to the nearest integer.
Input: Number
Output: Integer
Options: None
Example: 3.8 → floor becomes 3
round¶
Rounds to the nearest integer.
Input: Number
Output: Integer
Options: None
Example: 3.5 → round becomes 4
abs¶
Returns the absolute (positive) value.
Input: Number
Output: Number
Options: None
Example: -5 → abs becomes 5
at_least¶
Returns the larger of the number or a minimum value.
Input: Number
Output: Number
Options: value (minimum)
Example: price → at_least(10) ensures price is at least 10
at_most¶
Returns the smaller of the number or a maximum value.
Input: Number
Output: Number
Options: value (maximum)
Example: discount → at_most(50) ensures discount doesn't exceed 50
Date filters¶
date¶
Formats a date string using a format string.
Input: String (date in ISO format, e.g., "2025-03-27")
Output: String (formatted, e.g., "Mar 27, 25")
Options: format (format string using % codes), timeZone (IANA timezone, default "UTC")
Format codes:
- %Y — 4-digit year (2025)
- %y — 2-digit year (25)
- %m — 2-digit month (03)
- %d — 2-digit day (27)
- %b — short month name (Mar)
- %a — short weekday name (Thu)
- %H — 2-digit hour (14)
- %M — 2-digit minute (30)
- %S — 2-digit second (45)
Example: post_date → date("%a, %b %d, %Y") formats "2025-03-27" as "Thu, Mar 27, 2025"
Timezones: Use standard IANA timezone names: UTC, Europe/Paris, America/New_York, Asia/Tokyo, etc.
Filter combinations¶
You can chain filters together to combine transformations.
Example 1: List of formatted post dates
Gets all posts, extracts publish dates, takes the first, and formats it.Example 2: Post excerpt without HTML
Shortens the content to 200 characters and removes HTML tags.Example 3: Count of published posts
Filters to published posts and counts them.Common mistakes¶
- Using a filter on the wrong data type.
upcaseonly works on strings. Silex will prevent this in the editor. - Forgetting filter options. Some filters require options (
whereneedskeyandvalue). The editor will prompt you. - Chaining incompatible filters. If a filter outputs a number, the next filter must accept a number. Pay attention to input/output types.
- Not escaping special characters in options. If your
wherevalue contains quotes, make sure it's properly quoted.
Learn more¶
- Expressions — how filters fit into expressions
- Binding data — using filters in states
- Loops and lists — filtering lists for loops
- Liquid documentation — reference for filter behavior
Quiz¶
Q1: You want to extract the first 3 words from a post title. Which filter do you use?
- A)
truncate - B)
truncatewords - C)
slice
Answer
B) truncatewords — truncatewords limits a string to a number of words. truncate limits characters. slice works on arrays.
Q2: You have a list of posts and want to get only those published in the "news" category. What filter do you use?
- A)
find - B)
where - C)
slice
Answer
B) where — where filters a list by a condition. find returns the first match. slice extracts a range by index.
Q3: You want to add "$" to the beginning of a price. Which filter(s) do you chain?
- A)
prepend("$") - B)
plus("$") - C)
append("$")
Answer
A) prepend("$") — prepend adds to the beginning. append adds to the end. plus is for adding numbers.
Q4: You want to show the count of blog posts. What expression returns a number?
- A)
posts - B)
posts → size - C)
posts → count
Answer
B) posts → size — size returns the count of items in a list. posts alone returns the list itself, not a count.
Q5: You have a date "2025-03-27" and want to display it as "27/03/2025". What date format string do you use?
- A)
%d/%m/%Y - B)
%Y/%m/%d - C)
%d-%m-%Y
Answer
A) %d/%m/%Y — %d is day, %m is month, %Y is 4-digit year. This outputs day/month/year.