0

I have five exposed filter widgets that appear on this page. I would like to group three of them together and add a title above that group of three so that my layout goes from:

views default

  • A
  • B
  • C
  • D
  • E

what I want

  • A
  • TITLE

    • B
    • C
    • D
  • E

Since this customization is specific to one page, I added a views-exposed-form--mypage.tpl.php in my theme's template folder.

The code looks like this:

<div class="views-exposed-widgets clearfix">
    <?php foreach ($widgets as $id => $widget): ?>
      <div id="<?php print $widget->id; ?>-wrapper" class="views-exposed-widget views-widget-<?php print $id; ?>">
        <?php if (!empty($widget->label)): ?>
          <label for="<?php print $widget->id; ?>">
            <?php print $widget->label; ?>
          </label>
        <?php endif; ?>
        <?php if (!empty($widget->operator)): ?>
          <div class="views-operator">
            <?php print $widget->operator; ?>
          </div>
        <?php endif; ?>
        <div class="views-widget">
          <?php print $widget->widget; ?>
        </div>
      </div>
    <?php endforeach; ?>
    <?php if (!empty($sort_by)): ?>
      <div class="views-exposed-widget views-widget-sort-by">
        <?php print $sort_by; ?>
      </div>
      <div class="views-exposed-widget views-widget-sort-order">
        <?php print $sort_order; ?>
      </div>
    <?php endif; ?>

Instead of the foreach loop, how can I print the individual widgets?

1
<div class="views-exposed-widgets clearfix">
    <?php foreach ($widgets as $id => $widget): 
       if ($id == 'SOMETHING_ID_THATIDENTIFY_B') {
         print '<div id="BCD">'.t('TITLE');
       }
       else if ($id == 'SOMETHING_ID_THATIDENTIFY_E') {
         print '</div>'; //Closing #BCD
       }
    ?>

      <div id="<?php print $widget->id; ?>-wrapper" class="views-exposed-widget views-widget-<?php print $id; ?>">
        <?php if (!empty($widget->label)): ?>
          <label for="<?php print $widget->id; ?>">
            <?php print $widget->label; ?>
          </label>
        <?php endif; ?>
        <?php if (!empty($widget->operator)): ?>
          <div class="views-operator">
            <?php print $widget->operator; ?>
          </div>
        <?php endif; ?>
        <div class="views-widget">
          <?php print $widget->widget; ?>
        </div>
      </div>
    <?php endforeach; ?>
    <?php if (!empty($sort_by)): ?>
      <div class="views-exposed-widget views-widget-sort-by">
        <?php print $sort_by; ?>
      </div>
      <div class="views-exposed-widget views-widget-sort-order">
        <?php print $sort_order; ?>
      </div>
    <?php endif; ?>
  • Thanks! $id should be $widget->id, but otherwise it works! – Patrick Kenny Apr 4 '12 at 1:52

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.