Find processes templates by using handlebars.js
(for more information, see http://handlebarsjs.com/).
Each template file must produce HTML output that represents one document.
Find runs the templates with the following Handlebars context:
interface ResultTemplateData { reference: string; title: string; date: string; database: string; promotionName: string|undefined; summary: string; // The highlighted summary, should not be HTML escaped url: string|undefined; // URL of the original document or media file icon: string; // Icon class based on content type similarDocumentsUrl: string|undefined; // URL for linking to the similar documents view, only in result and promotion thumbnailSrc: string|undefined, // Source attribute to load the thumbnail in an <img> tag age: string; // Internationalised age of the document (e.g. "3 years ago") fields: {id: string, values: string[], displayName: string, advanced: boolean}[]; }
The following table also describes some Find custom helpers that you can use in your templates.
Helper | Description |
---|---|
equal
|
A block helper that takes two arguments. The block is printed only if the two arguments are referentially equal. |
hasField
|
A block helper that takes one string argument (the field). The block is printed only if the document has a value for the field. |
hasFieldValue
|
A block helper that takes two string arguments, the field and the value. The block is printed only if the document contains the specified value in the specified field. |
getFieldValue
|
Prints the first value for the specified field. |
getFieldValues
|
Prints all values for the specified field. You can optionally add the following parameters:
|
withField
|
A block helper that executes the block in the context of the given field. |
i18n
|
Prints a string from the application internationalization file. |
You reference fields in custom helpers by using the field ID (that is, the corresponding key in the fieldsInfo
section of the Find configuration file). Document fields are available only if you explicitly reference them in that configuration section.
The following template is a simple search result template that displays a thumbnail image for documents that contain a thumbnail
field. It also displays the document summary, an Author
field, and a link to get similar documents.
<div> <h1><i class="{{icon}}"></i>{{title}}</h1> {{#hasField 'thumbnail'}} <img src="{{thumbnail}}"/> {{/hasField}} <p>{{{summary}}}</p> <p>Author: {{getFieldValue "Author"}}</p> <a href="{{similarDocumentsUrl}}">See similar documents</a> </div>
|