Filter slice of strings using `where`

I have a slice of strings in $lines and want to filter out empty strings.

{{ range where $lines "." "!=" "" }}

doesn’t seem to work, neither does

{{ range where $lines "" "!=" "" }}

My current workaround for this is

{{ range $lines }}
{{ if ne . "" }}
...

However I was hoping to be able to do this only using where. Am I missing anything?

Another solution:

{{ range ($lines | complement (slice "")) }}
2 Likes

No. I think you got it right.

When using the sort function with a slice you can use the value keyword:

{{ sort $s "value" "asc" }}
{{ sort $s "value" "desc" }}

It would be convenient if you could do the same thing with where:

{{ where $s "value" "ne" "" }}

Deleted because already mentioned with complement (slice "").