Individually Print Exposed Filter Elements/Options 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:



To this:



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

    &lt;div class="views-widget"&gt;
      &lt;?php print $widget-&gt;widget; //this prints everything?&gt;
    &lt;/div&gt;


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.
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

unset($formArray['#options']);
$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 =&gt; $result) {
    if ($id &gt;= 0 &amp;&amp; $id &lt;= 2):
          $justColours['#options'][$id] = $result;
    elseif ($id &gt;= 3 &amp;&amp; $id &lt;= 4):
          justShades['#options'][$id] = $result;
    endif;
}


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

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


Snap!