Create Template Files
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}[]; weight: number; }
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 or more arguments. The block is printed only if the first argument is referentially equal to any of the subsequent arguments. |
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. You can also use getFieldValue as a block helper. |
getFieldValues
|
Prints all values for the specified field. You can also use getFieldValues as a block helper. 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. |
percentage
|
Formats the specified number as a percentage. You can optionally add the following parameters:
|
placeholderTemplate
|
Fills in a template that contains placeholder values, by using variables that you specify. This helper takes two arguments. The first argument is a hash, array, or string that defines the values to use in the specified template. The second argument is the template string that contains placeholder values. You can also optionally add the following parameters:
The placeholder value is a key that links to the values in your hash, array, or string. If you use a hash, you can use string keys. If you use an array or string value, use a zero-indexed numeric key that specifies which of the listed values to use. For example: {{ placeholderTemplate 'liftoff!,one,two,three' 'countdown: $3$, $2$, $1$, and $0$' placeholder='$' delimiter=','}} generates the string countdown: three, two, one, and liftoff!. |
prettyPrintNumber
|
Pretty-prints the specified number (for example, it converts 1000 to 1,000). You can optionally add the following parameters:
|
regexIf
|
A block helper that takes two string arguments, a regular expression and a string. The block executes if the regular expression matches the string. You can optionally add the following parameter:
|
toExternalUrl
|
Adds a URL schema prefix to the specified string, if it does not already have one. You can optionally add the following parameter:
|
toLowerCase
|
Converts the specified string to lower case characters. |
toUpperCase
|
Converts the specified string to upper case characters. |
toRelativeTime
|
Prints a specified date string as a relative time (for example, 50 years ago). You can optionally add the following parameters:
|
wikiThumbnailHelper
|
Converts a Wikipedia Commons image URL to one with a fixed thumbnail size. This helper takes two arguments. The first argument is the URL, and the second is the maximum thumbnail width (in pixels). |
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.