I'm using Better Exposed Filters on a view and want to individually print the elements/options within the 'widget', rather than all of them at once.

For example, lets say my options are: Red, Yellow, Green, White and Black, I want to be able to print Red, Yellow and Green in one , then White and Black in another.

From this:

enter image description here

To this:

enter image description here

The the template appears to only allow for an all or nothing approach:

    <div class="views-widget">
      <?php print $widget->widget; //this prints everything?>

I imagine I could print the entire widget a number of times, then hide specific elements using CSS, but I feel this would create a a bit of a performance hit.

I've also tried separating options into different filters, but more than one exposed filter crashes my site as soon as the user selects options in more than one filter.

  • have you got devel installed? Try placing a dsm($widget); in the php and see what variables you have to play with
    – Collins
    Commented Aug 10, 2016 at 7:05
  • I've been able to find the variables I have to play with, but completely unable to figure out how to render them individually
    – Simo
    Commented Aug 10, 2016 at 7:25

1 Answer 1


I found a fairly reasonable solution to this - there may be better ways, but so far it works without any performance hit that I have been able to detect.

It seems as it's a fairly complex multidimensional array, you can only render an entire widget or not. So to do this you need to create different versions of the widget, with different options inside them, and render them in their entirety.

Step 1: Copy the form array (the widget) into a new array and create another array containing just the options

$formArray = $form['colours'];
$allColours = $form['colours']['#options'];

Step 2: Unset all the options from the new array, which is now just a shell, then create a few copies of it

$justColours = $formArray;
$justShades = $formArray;

Step 3: Cycle through your array containing just the options, and distribute them back into the shells you created

foreach ($allColours as $id => $result) {
    if ($id >= 0 && $id <= 2):
          $justColours['#options'][$id] = $result;
    elseif ($id >= 3 && $id <= 4):
          justShades['#options'][$id] = $result;

Step 4: Render your new arrays where you need 'em

print render($justColours);
print render($justShades);


Your Answer

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

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