How to replace an unfiltered Search API results view with custom text? Setting: using the search_api_views module, I have created a view with an exposed fulltext search filter. In addition, I have lots of facets for the corresponding search index in a separate block (via the search_api_facetapi module). Searching and filtering works well.

Question: When no facet item is selected and no fulltext search is used, then all indexed nodes are shown in the view as search results. How can I replace this full nodes list with a custom text (e.g., “Enter a search term or select a facet item to filter our products.”)? In other words: how can I hide the results list if and only if no search filter (facet or fulltext) is applied?
Here’s how I solved this:

First I implemented hook_views_post_build. Note, that I could have probably used most other views processing hooks, too, as I’m only adding custom build information.



/**
 * Implements hook_views_post_build().
 */
function MY_MODULE_views_post_build(&amp;$view) {

  // If there is no explicit search being done, then we show a message instead
  // of all search results. We still have to run the search under the hood so
  // that we have correct search facets available. Therefore we could have also
  // used most other views processing hooks here.
  if ($view-&gt;name === 'MY_VIEW_NAME' &amp;&amp; empty($view-&gt;exposed_input['f'])
       &amp;&amp; empty($view-&gt;exposed_input['search'])) {
    $view-&gt;build_info['MY_MODULE_show_message'] = TRUE;
  }
}


Then I added my custom message to an overridden views-view.tpl.php using the previously defined build info variable:

&lt;!-- … views template header here … --&gt;
&lt;div class="&lt;?php print $classes; ?&gt;"&gt;

  &lt;?php if (isset($view-&gt;build_info['MY_MODULE_show_message'])): ?&gt;
    &lt;h2&gt;My Custom Message&lt;/h2&gt;
    &lt;p&gt;Enter a search term or select a facet item to filter our products.&lt;/p&gt;
  &lt;?php else: ?&gt;
    &lt;!-- … normal views content here … --&gt;
  &lt;?php endif; ?&gt;

&lt;/div&gt;&lt;?php /* class view */ ?&gt;