Share » Forums » Developer » search result highlighted with search...

search result highlighted with search keyword

search result highlighted with search keyword

Monday 14 September 2009 11:54:54 pm - 5 replies

Modified on Tuesday 15 September 2009 3:31:06 am by manoj sharma

Author Message

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

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu