Brief: How to add a custom field from a taxonomy term into a View's exposed filter form?

Specific: I have an image field added to taxonomy terms that I want to add to the exposed filter form along with the radio button and the TID's name (default is only radio + name), themed with Twig template.

More words:
I'd like to modify an exposed Views filter form to include the rendered image field from the taxonomy terms listed in the exposed filter. I've run into several dead ends getting this to work in Drupal 9.x. Some of the instructions I've found seem to be either for older versions, or I'm just unable to sort this out.

My View is set up to have "Content: Has taxonomy term ID" contextual filter, with the appropriate settings for the filter criteria. Everything works great for the exposed filter on the target page.

The term itself has the added field of a Media image, which works fine when visiting the term's page, for instance.

I've tried many different things, but most recently I am using the Better Exposed Filters module, with the results displayed as "inline" and I have a Twig template that overrides the output (/templates/views/views-exposed-form--[view-name]--[display-name].html.twig), which does work.

I'm stuck getting any access to the actual custom field from the taxonomy term! I can access everything from the base TID & name, etc., but I can't figure out how to get at the extra field so I can try to render it in the Twig template.

Stuff I tried and/or don't understand:

I'd prefer to do this purely in Twig templates (unless that's dumb?), but I also will do a simple module with a hook_form_alter if it is better... I'm admittedly new to Drupal 8/9 (I'm trying to migrate an old Drupal 7 site), so I figure I'm missing some things here.

THANK YOU for any help/ideas making this ugly form look purty!!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.