Normally the Page_results.ss look like this:
<ul id="SearchResults"> <% control Results %> <li> <a href="$Link"> <% if MenuTitle %>$MenuTitle<% else %>$Title<% end_if %> </a> <p>$Content.ContextSummary</p> <% end_if %> </li> <% end_control %> </ul>
If you want to highlight your search query, add this function to Page.php:
public function SentenceContainingQuery() { $query = Controller::curr()->Query; $content = $this->obj('Content'); $sentences = explode( '.', $content->NoHTML()); if ( count($sentences) ) { foreach($sentences as $sentence) { if ( strchr($sentence,$query) ) { return str_replace($query, "<span class='query-instance'>$query</span>", $sentence) . '.'; } } } else { $sentence = $content->FirstSentence(); return str_replace($query, "<span class='query-instance'>$query</span>", $sentence) . '.'; } }
In Page_results.ss add following code:
<ul id="SearchResults"> <% control Results %> <li> <a class="searchResultHeader" href="$Link"> <% if MenuTitle %>$MenuTitle<% else %>$Title<% end_if %> </a> <% if SentenceContainingQuery %> <p>$SentenceContainingQuery</p> <% end_if %> </li> <% end_control %> </ul>
And Last the css:
span.query-instance { font-weight: bold; background: #CCC; }
Looking for quality SilverStripe Web Hosting? Look no further than Arvixe Web Hosting!