2

I have a views exposed filter block that I'm using as a search form. I'm wondering how I can display static text within the block. Here's what my Block looks like:

enter image description here

Essentially I want to display the title (Find A Venue) to the left of the fields, and then display the word "or" between the two. If somebody knows how to move the block title to the left of the filter fields instead of above, I suppose that that would serve my purpose well enough as well. Although, it would be nice to know how to display the static text regardless.

2

You can do this with Better Exposed Filters.

Enable the module and then navigate to your view edit page. Under Exposed Form, click Basic, which is next to Exposed form style, and change it to Better Exposed Filters. Add a Description of "or" to your title. This will place the text on the page; you will then need to style it with CSS to place it where you want.

  • Interesting strategy. I hadn't thought of adding it with BEF and then styling it. Looks like it's working pretty well. I didn't think of just moving the placement of the Title using css either. Aside from adding it in with BEF, do you know of any way to insert static text? Not that I need it at the moment, but it just seems odd that that wouldn't be something supported out of the box. – Mrweiner Jun 24 '12 at 2:07
  • You could also probably override the Views template. – Patrick Kenny Jun 24 '12 at 2:59
  • 1
    What do you mean by "Add a Description of "or" to your title" Do I add another filter criteria or is there an option in the BEF setting which I missed? – user29110 May 15 '14 at 12:08
2

Since an exposed filter is a form you could of course use hook_form_alter to tweak the form in any way you want.

0

I know this is a really old question, but here's what I did for Drupal 8. I hope it helps someone. (This is for a views page with the exposed filters exposed as a block).

use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_form_FORM_ID_alter().
 */
function my_module_form_views_exposed_form_alter(array &$form, FormStateInterface $form_state, $form_id) {

  switch ($form['#id']) {
    case 'my_views_exposed_form_id':

      $form['my_text'] = array(
        '#type' => 'item',
        '#markup' => t('This is some custom text'),
        '#weight' => 0, // experiment with negative / positive weights to see what works
        '#wrapper_attributes' => ['class' => ['my_class']],
      );
      break;
  }
}

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.