3

I want to change the default search help text 'Check if your spelling is correct. Remove quotes...' that is displayed when there are no results.

What's the best method of practice for this? Should I override the value in a template.php function? If so how do I go about this?

3 Answers 3

8

The easiest thing for you to do would be to override the actual template file which displays that language.

Look at the template file called search-results.tpl.php in the core search module.

It has the following code at the bottom:

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

Copy the entire template file (you don't even need to rename it, it'll override the file in the module) and paste it into your own theme's /templates folder. Re-write the section I've pasted at the top to be whatever you want. The part that prints the search_help() is the bulleted list you're looking to change.

Of course, before the system will pick up your new template file, you need to clear all your caches!

Let us know if this works!

1
  • Sorry I meant the best way to do it programmatically. Could you provide a solution for this also please? Commented Oct 12, 2012 at 11:06
0

This works via hook_page_alter so can be placed in a custom module. It replaces the empty results with a single fake result. So the standard no results test does not get displayed, and you can set here what it actually shown instead.

/***
 * Implement hook_page alter.
 * Here we override what gets displayed on the search page when no results are found.
 **/
function MYMODULE_page_alter(&$page) {
  // Reference the search results (if present).
  $results = &$page['content']['system_main']['search_results']['#results'];
  // If we are on the search results page but there are no results...
  if (isset($results) && empty($results)) {
    // Replace empty results with a single fake result showing info.
    $results = array(
      array(
        'title' => '',
        'link' => '',
        // Display the translated standard message (or whatever you want).
        'snippet' => t('Your search yielded no results'),
      ),
    );
  }
}
0

I'm using ds_search and neither of the answers here worked for me. What did work was to install the stringoverrides module, then visit /admin/config/regional/stringoverrides. I put the entire text of the no results t() string in the "Original" column, then the text I wanted in the replacement column.

Be sure to grab the full text of the original string found in Core's search.module file. It should be something like this:

<ul>
 <li>Check if your spelling is correct.</li>
 <li>Remove quotes around phrases to search for each word individually. <em>bike shed</em> will often show more results than <em>&quot;bike shed&quot;</em>.</li>
 <li>Consider loosening your query with <em>OR</em>. <em>bike OR shed</em> will often show more results than <em>bike shed</em>.</li>
</ul>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.