Drupal - Highlight searched keyword using exposed filter views?

Using search_excerpt function you can highlight the searched keyword. It show the keyword in bold.

Returns snippets from a piece of text, with certain keywords highlighted. Used for formatting search results.

An example is shown below,

for eg: //a body field is exposed here

in your views tpl file add the following code

 <?php foreach ($rows as $id => $row): 

      $keys = $_GET['body_value'];
      $row = search_excerpt($keys, $row);
 ?>

it will highlight the searched word, see the screenshot below

enter image description here


You could use something like highlight that finds and adds a class to all instances of a word on the page, and instead of feeding it a static word, you would use the contents of the search box.

You can find more information and links to other versions in the StackOverflow question, Highlight a word with jQuery.

Tags:

Search

Views