compact
Remove all nil elements from an array, returning a clean array containing only defined values.
Syntax
{{ array | compact }}Example
{% assign list = "Austin,Dallas,Houston" | split: "," %}{{ list | compact | join: ", " }}Output
Austin, Dallas, HoustonThe compact filter scans an array collection and strips away any elements that evaluate to nil, returning a purified array containing only non-empty, defined items for safe downstream operations.
In programmatic SEO templates, compact filters sparse multi-column attribute sets when combining feature badges. For example: {% assign features = row.amenities | split: ';' | compact %}. Iterating over this cleaned array ensures no blank bullet items or awkward empty tags are rendered on the public landing page, preserving high layout quality.
Filters
- abs
- append
- at_least
- at_most
- capitalize
- ceil
- compact
- concat
- date
- default
- divided_by
- downcase
- escape
- escape_once
- first
- floor
- join
- last
- lstrip
- map
- minus
- modulo
- newline_to_br
- plus
- prepend
- remove
- remove_first
- replace
- replace_first
- reverse
- round
- rstrip
- size
- slice
- sort
- sort_natural
- split
- strip
- strip_html
- strip_newlines
- times
- truncate
- truncatewords
- uniq
- upcase
- url_decode
- url_encode
- where
- raw
- slugify
- number_format
