1

I have a collection of namedtuples which looks like this :

[('mountpoint=X',state='UP'),(mountpoint='Y',state='DOWN'),(mountpoint='Z',state='DOWN'...)]

I pass this collection to one of my templates. I'd like to filter that collection based on state. Tried the following to no avail

  {% for state in states|selectattr('state','down') %}
TemplateRuntimeError: no test named 'down'

  {% for state in states|selectattr(state='down') %}
FilterArgumentError: Missing parameter for attribute name

  {% for state in states|select(state='down') %}
No error, but doesn't filter at all.
vaultah
  • 44,105
  • 12
  • 114
  • 143
ychaouche
  • 4,922
  • 2
  • 44
  • 52

1 Answers1

2

Use the equalto test:

{% for state in states|selectattr('state', 'equalto', 'down') %}
vaultah
  • 44,105
  • 12
  • 114
  • 143