I18N Search - Custom Rendering
By specifying a component name as parameter to the search call, you can render the search result in a different way, e.g.
(% searchresults tags=products component=renderproduct %)
In the component you have access to the following variables:
-
$item: the page or other item found: the properties and methods accessible by $item->propname include:
- tags (array of strings),
- title and content,
- pubDate and creDate (publishing and creation date, both as UNIX timestamps),
- any custom fields
-
getExcerpt($text, $length): returns an excerpt of $text in the requested $length
- $showLanguage: true, if the language should be shown
- $showDate: true, if the date should be shown
- $dateFormat: date format for strftime
- $numWords: the number of words requested in the excerpt
A component rendering the page in the default way would look like:
<h3 class="search-entry-title"> <?php if ($showLanguage) { ?> <span class="search-entry-language"> <?php echo htmlspecialchars($item->language, ENT_NOQUOTES); ?> </span> <?php } ?> <a href="<?php echo $item->link; ?>"> <?php echo htmlspecialchars($item->title, ENT_NOQUOTES); ?> </a> </h3> <?php if ($showDate) { ?> <div class="search-entry-date"> <?php echo strftime($dateFormat, $item->pubDate); ?> </div> <?php } ?> <div class="search-entry-excerpt"> <?php echo $item->getExcerpt($item->content, $numWords); ?> </div>
Example
Here is an example of rendering the special pages for software with a component, whereas normally they would be rendered like here.