How to print custom text on search no result with search-results.tpl.php? I want to print custom text if there is no result on search.

I'm using custom search-result.tpl.php and search-results.tpl.php.

My search-results.tpl.php is that:

     &lt;?php if ($search_results): ?&gt;
      &lt;h2&gt;&lt;?php print t($search_totals);?&gt;&lt;/h2&gt;
      &lt;div class="view-content"&gt;
        &lt;table class="views-table cols-4 search-results &lt;?php print $module; ?&gt;-results table table-striped"&gt;
.../* my results style here */
        &lt;tbody&gt;
            &lt;?php print $search_results; ?&gt;
        &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/div&gt;
      &lt;?php print $pager; ?&gt;


    &lt;?php else : ?&gt;
      &lt;h2&gt;&lt;?php print t('Your search yielded no results');?&gt;&lt;/h2&gt;
      &lt;?php print search_help('search#noresults', drupal_help_arg()); ?&gt;
    &lt;?php endif; ?&gt;



It works correctly if there are search results but if there is no result it doesn't print anything although there is the &lt;?php else : ?&gt; part.


How can I print custom text if there is no result?
The core Drupal search module uses several template files that dictate both how search results are displayed, and what's displayed when there are no search results.

If you're already using a custom theme on your Drupal site, the best way to customize those would be to copy and paste the entire 'search-results.tpl.php' file from the search/ module folder into your own custom theme subfolder.

Open that file up for editing and you'll see the following at the bottom:

&lt;?php else : ?&gt;
  &lt;h2&gt;&lt;?php print t('Your search yielded no results');?&gt;&lt;/h2&gt;
  &lt;?php print search_help('search#noresults', drupal_help_arg()); ?&gt;
&lt;?php endif; ?&gt;


This is what's displayed if search results are not found (thus the 'else')...  Modify the text to be anything you want here.  The second line, which calls the search_help() function is the one that displays the search suggestions.  Feel free to replace that too....

And as always, before you can see your changes, you'll probably need to clear cache!