search result highlighted with search keyword

Author Message

manoj sharma

Monday 14 September 2009 11:54:54 pm

Hi guyz,

is there any way through which i can make my search result highlighted with some color.

the word which user uses should be highlighted.

example:
user has made a search on "web development".

web development is search keyword, so whenever "web development" comes in the content or in the result.. web development should be highlighted with some color.

i am using ezpublish 4.0.1 with ezflow and ezwebin.

thanks & regards,
Manoj Sharma

Jean-Luc Nguyen

Tuesday 15 September 2009 3:36:12 am

Hello,

You can create a new operator, equivalent of php function str_replace().

When you are displaying your results, writing something like:

{foreach $results as $result}
{str_replace( $keyword, concat( '<span style="color:red">', $keyword, '</span>' ), $result.name )}
{/foreach}

Where $results is your search array results, $result is each line of result, and $keyword is your search word.

http://www.acidre.com

manoj sharma

Tuesday 15 September 2009 5:47:37 am

i couldn't found the foreach loop to do this.
i am not fluent with ezpublish..
please elaborate more..

thanks & regards,
Manoj

Jean-Luc Nguyen

Tuesday 15 September 2009 7:28:28 am

First, check the default search template code: design/standard/templates/content/search.tpl and searchresult.tpl. On this template, you may have something like:

{section name=SearchResult loop=$search_result show=$search_result sequence=array(bglight,bgdark)}

which is the equivalent of the foreach loop

http://www.acidre.com

manoj sharma

Wednesday 16 September 2009 12:26:48 am

Thanks Jean-Luc Nguyen for taking out time for my post.

but had no luck with searchresult.tpl.

Whatever changes i does on search.tpl or searchresult.tpl. is not viewable on frontend, and there are no override files for them either.

as far as i have studies the code,
ezpublish uses ezwebin/design/ezwebin/override/templates/line and files in it to show search result, for folder it will use folder.tpl and for article it will use article.tpl.

what i want is a common script to highlight the searched word (both in heading and in description)..

is there any common way to do this?

Thanks & Regards
manoj

 

Jean-Luc Nguyen

Wednesday 16 September 2009 12:47:23 am

Hello,

I think that before trying to highlight your search results, try to override default search templates; do not edit design/standard/templates/content/search.tpl and searchresult.tpl, but override them by creating them on your extension, something like extension/your_extension/design/your_frontoffice_design/templates/content/search.tpl and searchresult.tpl.

http://www.acidre.com

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.