What do I have to do to override the message

Your search yielded no results

from core search module inside core/modules/search/src/Controller/SearchController.php?


You can implement template_preprocess_item_list (or hook_preprocess_HOOK to be precise) in your theme or module to override that.

 * Implements template_preprocess_item_list().
function MYTHEME/MYMODULE_preprocess_item_list__search_results(&$variables) {

  $variables['empty']['#markup'] = '<h3>' . t('Foobar') . '</h3>';
| improve this answer | |

You can replace empty search message by call custom block body by:

  • Go to /code/themes/THEMENAME
  • open THEMENAME.theme file and add following Hook


function THEMENAME_preprocess_item_list__search_results(&$variables) {
  $custom_block = \Drupal::entityTypeManager()->getStorage('block_content')->load('BLOCKNUMBER');
  $fieldcontent = $custom_block->body->value;
  $variables['empty']['#markup'] = $fieldcontent;

Please change THEMENAME with you theme name and BLOCKNUMBER with your block number.

| improve this answer | |

You can do this by String Overrides module. I just do that in fresh drupal 8 setup. Please check below screenshot. enter image description here

And update message on frontend.

enter image description here

| improve this answer | |
  • Thanks for your reply.I have already try with this.But it is not working. – salu Jul 25 '18 at 10:58
  • It's working. Please add this "Your search yielded no results." In configuration Page. If issue let me know. – Pankaj Yogi Jul 25 '18 at 11:08

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.