4

There is a content type and it has a field called field_type. It's a select list and there is 5 options to select such as AAA, BBB, CCC, DDD, EEE.

I'm using the Views module to list the nodes of this content type. I added the field_type as exposed filter for this views.

In the header of the views, I added the Global: Result summary to show result summary.

 "@total results found."

enter image description here

What I want to do is dynamically change the text based on the exposed filter. For example if the AAA is selected on the field_type exposed filter then the results summary should display:

 "@total AAA found."


How can I do that?

  • Did you have a chance to try out the module I posted? I believe it answers your question and solves your problem. You can install it as a you would with any other contrib module. Cheers – Stefanos Petrakis Feb 16 '16 at 8:10
1

I took the liberty of writing a little module for accomplishing what you asked for, I found it an interesting problem. You can access it here:

https://www.drupal.org/sandbox/stefanos.petrakis/2666048

Hope this helps

  • Thanks for your answer and for the "sandbox" module. I have to learn how to use this kind of modules :) – herci Feb 13 '16 at 21:23
  • Do give it a try and please let me know if you have any questions. – Stefanos Petrakis Feb 13 '16 at 22:51
  • Unfortunately it gives some error. I will try to solve the errors myself, if I couldn't I will write them here. Thanks. – herci Feb 16 '16 at 11:45
  • Hello @herci. Did you get this to work? What is the problem you are facing with installing this module? Cheers – Stefanos Petrakis Mar 2 '16 at 23:06
1

This can be done by implementing the hook_views_pre_render and altering the view's header content. Here is a sample code:

/**
 * Implements hook_views_pre_render().
 */
function my_module_views_pre_render(&$view) {
  if ($view->name == 'my_view' && $view->current_display == 'my_display') {
    $indicator = $view->exposed_input['my_filter'] == 1 ? t('AAA ') : t('BBB ');
    $view->header['result']->options['content'] = '<div class="my-class-results">@total <strong><em>' . $indicator . '</strong></em> found</div>';
  }
}

This works with any substitution: @start, @end, @total, @name etc

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.