I implemented a view as following :
- a page display with an extensive exposed filters form (Better exposed filters), ajax enabled, let's call it the landing page
- a clone of it, in a second page display with exactly the same fields, but few exposed filters instead (quick search form)
- that clone has exactly the same path, Exposed form in block is set to yes
I display the clone created block (quick search form) on homepage : submitting its form redirects to landing page with correct results and the complete exposed filters. This is fine.
Question :
I need to display a results count next to the exposed form block, which refreshes each time you change a exposed filter value in the form.
The Global: Result summary in header or footer doesn't work because footer and header aren't displayed together with the exposed block, they only come with the full view display.
How could solve that, either with UI or programmatically ? Below some ideas to begin, there might be a good and straight way :
- force the results count header to be displayed next to exposed block ?
- add a markup to the form with ajax results ?
- create another block ?
EDIT
I tried several approaches based on Shreya answer below, but the blocking point is always the same, I need to execute the view to get result count, but as soon as I do, it returns an Allowed memory size exhausted.
in template.php :
function shoot_preprocess_views_exposed_form(&$vars){
if($vars['form']['#id'] == 'views-exposed-form-customer-products-list-search-block') {
$view = views_get_view('MY_VIEW');
$view->set_display('MY_DISPLAY');
$view->execute();
$count = count( $view->result );
$vars['count'] = $count;
}
}
in views-exposed-form--MY_VIEW.tpl.php
print 'There are:'. $count. 'results';
And other tries with views_get_current_view()
or views_get_view_result()
in the tpl, also tried within form alter :
function MYMODULE_form_views_exposed_form_alter(&$form, &$form_state, $form_id) {
if($form['#id'] == 'views-exposed-form-my-view-my-display') {
$view = views_get_view('MY_VIEW');
$view->set_display('MY_DISPLAY');
$view->get_total_rows = true;
$view->pre_execute();
$view->preview('MY_DISPLAY');
$view->execute();
$content = $view->total_rows;
}
$form['submit']['#value'] = 'Voir les'. $content.' résultats';
}
Any clue to explain why I can't execute the view, or how to return count in that context ?