clean

Drops the elements that hold nothing, so a list can be built by appending unconditionally and tidied once at the end instead of being guarded at every append.

Order is kept and the remaining elements are untouched.

Nothing means nil, an empty string, and an empty list or object. Zero and false are real values and stay, which is the same line default draws between absent data and a value that happens to be empty.

InputArgumentsReturns[]anyno arguments[]any
Source
BasicSource

Drops the elements that hold nothing, so a list can be appended to unconditionally and tidied once at the end.

Given

{"parts": ["one", "", nil, "two"]}

Template

{{ parts | clean }}

Result

[
  "one",
  "two"
]
Empty collectionsSource

Treats an empty list or object as an element holding nothing, so a build-up of optional groups comes out with only the groups that were filled.

Given

{"groups": [["a"], [], {}]}

Template

{{ groups | clean }}

Result

[
  [
    "a"
  ]
]
Keeps zeroSource

Keeps zero and false, which are real values, and drops only the elements that hold nothing.

Given

{"counts": [0, nil, false, ""]}

Template

{{ counts | clean }}

Result

[
  0,
  false
]