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, Houston

The 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.

Try this syntax in the editor.