I need to print out a list of checked form options in a TWIG template in Drupal 8.

I'm using Better Exposed Filters, and editing the views-exposed-form.html.twig template.


Iterate over the form options, returning the # value of each item:

{% for choice in form.filter['#value'] %}

Then Print out the title value of each one of those options:

{{ form.filter[choice]['#title'] }}

All together it looks like this:

{% for choice in form.filter['#value'] %} {# Find each checked option #}
  {{ form.filter[choice]['#title'] }} {# Print the Title #}
{% endfor %}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.