Drupal 8 Views - Markup inside labels?
October 19th 2020
I was required to add a logo inside a label using exposed filters from a Drupal 8 View. After doing some brainstorming with other colleagues about: how do we approach this (not everyday you have a checkbox + logo + text), and mostly since is the only checkbox in the entire project with an icon in it, we were wondering if actually we need to implement a `hook` that will work sitewide for all the exposed filters allowing us to create a new template for each one of the filters (if needed), and suddenly I tested adding some HTML markup inside the `Label` field directly in the UI.
I went down the road and added:
1 <span>This is a span test </span>Filter all results using Drupal 9
The result was something I was not expecting, since my first thought (and my best) was: alright, Drupal is going to remove the markup and will possibly print just the string inside the `<span>`.
But for my surprise I was totally wrong
The output from that was:
Which lead me to think, great! this may open many possibilities to implement new designs and interaction with users, but how much we can get from this?
Well, I set the filter to be as a small example of let's call it "possible checkbox design"
1 Show <b>only</b> results using <img src="https://www.drupal.org/files/Wordmark_blue_RGB.png" alt="Drupal Logo">
And the result once again, surprised me..
This may not change all we do everyday, but definitely opens new possibilities where designs require this type of features, or I'd say it gives more flexibility to designers when doing some cool fancy looking filters and in the other side of the spectrum, less custom code in our projects