Interface ICoreHelpers

The core template helpers provided by default.

Examples:

HTML

<div class="CoveoFieldValue" data-field="@videoduration" data-helper="timeSpan" data-helper-options-is-milliseconds="false"></div>

Underscore

<%= timeSpan(raw.videoduration, { isMilliseconds: false }) %>

Index

Properties

anchor

anchor: function

Formats a clickable HTML link (<a>).

Type declaration

currency

currency: function

Formats a currency value to a string using the specified options.

Type declaration

date

date: function

Formats a date value to a date-only string using the specified options.

  • content: The Date value to format.
  • options: Optional. The options to use (see IDateToStringOptions).

Type declaration

dateTime

dateTime: function

Formats a date value to a date and time string using the specified options.

  • content: The Date value to format.
  • options: Optional. The options to use (see IDateToStringOptions).

Type declaration

email

email: function

Renders one or several email values in mailto: hyperlinks.

  • value: The string or array of strings that contains a list of semicolon-separated email values. When multiple values are passed, each value is displayed in a separate hyperlink.
  • companyDomain: Optional. The string that contains your own domain (e.g.: coveo.com). When specified, this parameter allows email addresses coming from your own domain to be displayed in a shortened format (e.g.: Full Name), whereas email addresses coming from an external domain will be displayed in an extended format (e.g.: Full Name (domain.com)). If this parameter is not specified, then the shortened format will automatically be used.
  • me: Optional. The string that contains the current username. If it is specified, then the email address containing the current username will be replaced by the localized string 'Me'.
  • lengthLimit: Optional. The number of email addresses that you want to display before an ellipse is added (e.g.: 'From Joe, John and 5 others').
    The default value is 2.
  • truncateName: Optional. When the username is available from the email address, then you can specify if you want to truncate the full name. (e.g.: 'John S.' instead of 'John Smith').
    The default value is false.

Type declaration

    • (value: string | string[], companyDomain?: string, me?: string, lengthLimit?: number, truncateName?: boolean): string
    • Parameters

      • value: string | string[]
      • Optional companyDomain: string
      • Optional me: string
      • Optional lengthLimit: number
      • Optional truncateName: boolean

      Returns string

emailDateTime

emailDateTime: function

Formats a date value to a date and time string using options suitable for email dates

  • content: The Date value to format.
  • options: Optional. The options to use (see IDateToStringOptions).

Type declaration

encodeCarriageReturn

encodeCarriageReturn: function

Replace all carriage return in a string by a <br /> tag

  • value: The string value to replace the carriage returns in.

Type declaration

    • (value: string): string
    • Parameters

      • value: string

      Returns string

fromFileTypeToIcon

fromFileTypeToIcon: function

Generates an icon based on the file type of the current result. The icon will be contained inside a <span> element with the appropriate CSS class.

  • result: Optional. The current result object inside your template. In underscore, it is referenced as obj. By default, the result will be resolved automatically from your current template function ( Meaning the nearest result in the current call stack execution inside your template)
  • options: Optional. The options to use (see IIconOptions).

Type declaration

    • Parameters

      Returns string

highlight

highlight: function

Highlights a string using the provided highlight information.

  • content: The URI to shorten.
  • highlights: Optional. The highlight information to use.
  • cssClass: Optional. The name of the CSS class to use for highlighting.

Type declaration

    • (content: string, highlights?: IHighlight[], cssClass?: string): string
    • Parameters

      • content: string
      • Optional highlights: IHighlight[]
      • Optional cssClass: string

      Returns string

highlightStreamHTML

highlightStreamHTML: function

This helper operates exactly like the highlightStreamText helper, except that it should be used to highlight HTML content. The helper takes care of not highlighting the HTML markup.

Note:

highlightStreamHTML should only be used for very particular/specific use cases (e.g., augmenting the result template with additional information rather than the typical excerpt/title), and is not a proper replacement for actually having the correct title and excerpt on your results.

Using incorrect result titles or excerpts on your search interface also causes relevancy to suffer greatly, as the index uses the title and excerpt to find relevant results. Consequently, end users are more likely to see results whose titles do not match their query.

Moreover, the recommended method to implement simple title and/or excerpt highlighting is to simply use the Excerpt and ResultLink components.

Type declaration

highlightStreamText

highlightStreamText: function

Highlights the provided terms in a given string.
By default, the terms to highlight are the current query and the associated stemming words from the index. The only required parameter is the content, which specify the string that needs to be highlighted. The other parameters will normally be automatically resolved for you from the current result object.

Note:

highlightStreamText should only be used for very particular/specific use cases (e.g., augmenting the result template with additional information rather than the typical excerpt/title), and is not a proper replacement for actually having the correct title and excerpt on your results.

Using incorrect result titles or excerpts on your search interface also causes relevancy to suffer greatly, as the index uses the title and excerpt to find relevant results. Consequently, end users are more likely to see results whose titles do not match their query.

Moreover, the recommended method to implement simple title and/or excerpt highlighting is to simply use the Excerpt and ResultLink components.

Type declaration

image

image: function

Formats an HTML image tag (<img>).

  • src: The image source URI
  • options: Optional. The options to use (see IImageUtilsOptions)

Type declaration

isMobileDevice

isMobileDevice: function

Detect if the results is being rendered in a mobile device.

If it's not a mobile device, the helper return null ;

If it's a mobile device, return the type of device (Android, iPhone, iPad) etc.

Type declaration

    • (): string
    • Returns string

loadTemplate

loadTemplate: function

Loads a partial template in the current template, by passing the ID of the template to load, the condition for which this template should be loaded, and the context object (the object that the loaded template will use as its data). By default, the context object will be the same as the template that called this helper function. So, for example, in a ResultList Component, the contextObject would, by default, be the Query Results.

  • templateId: The ID of the template to load.
  • condition: Optional. The boolean condition to determine if this template should load for this result set. Most of the time this would be a condition of the type if raw.somefield == 'something'.
  • contextObject: Optional. The object that should be used by the loaded template as its contextObject.

Type declaration

    • (templateId: string, condition?: boolean, contextObject?: any): string
    • Parameters

      • templateId: string
      • Optional condition: boolean
      • Optional contextObject: any

      Returns string

number

number: function

Formats a numeric value using the format string.

  • content: The numeric value to format.
  • format Optional. The string format to use. See the Globalize library for the list of available formats.

When the helper is used in a FieldValue component, this value is automatically retrieved from the specified field.

Example:

 <div class="CoveoFieldValue" data-field="@viewcount" data-text-caption="Views" data-helper="number" data-helper-options-format="n0"></div>

Type declaration

    • (content: string, format: string | INumberFormatOptions): string
    • Parameters

      • content: string
      • format: string | INumberFormatOptions

      Returns string

shorten

shorten: function

Shortens a string so that its length does not exceed a specific number of characters. An ellipsis is appended to the string if it exceeds the maximum length.

  • content: The string to shorten.
  • length: The maximum length of the resulting string.
  • highlights: Optional. If provided, the string will be highlighted using this highlight information.
  • cssClass: Optional. When highlighting, the name of the CSS class to use.

Type declaration

    • (content: string, length: number, highlights?: IHighlight[], cssClass?: string): string
    • Parameters

      • content: string
      • length: number
      • Optional highlights: IHighlight[]
      • Optional cssClass: string

      Returns string

shortenPath

shortenPath: function

Shortens a string using an algorithm suitable for file paths. The helper will insert an ellipsis in the string where text has been removed when the path exceeds the maximum length.

  • content: The path to shorten.
  • length: The maximum length of the resulting string.
  • highlights: Optional. If provided, the string will be highlighted using this highlight information.
  • cssClass: Optional. When highlighting, the name of the CSS class to use.

Type declaration

    • (content: string, length: number, highlights?: IHighlight[], cssClass?: string): string
    • Parameters

      • content: string
      • length: number
      • Optional highlights: IHighlight[]
      • Optional cssClass: string

      Returns string

shortenUri

shortenUri: function

Shortens a string using an algorithm suitable for URIs. The helper will insert an ellipsis in the string where text has been removed when the URI exceeds the maximum length.

  • content: The URI to shorten.
  • length: The maximum length of the resulting string.
  • highlights: Optional. If provided, the string will be highlighted using this highlight information.
  • cssClass: Optional. When highlighting, the name of the CSS class to use.

Type declaration

    • (content: string, length: number, highlights?: IHighlight[], cssClass?: string): string
    • Parameters

      • content: string
      • length: number
      • Optional highlights: IHighlight[]
      • Optional cssClass: string

      Returns string

size

size: function

Formats a number, which represents a file size in bytes, into a logical unit size.

Examples:

size(1024) => 1024 B

size(1025) => 1 KB

size(10240) => 10 KB

Examples:

HTML

<div class="CoveoFieldValue" data-field='@size' data-helper="size" data-helper-options-base="1"></div>

Underscore

<%= size(raw.size, {base: 0, precision: 2}) %>
  • value: The number to format
  • options : The options to use (see ISizeOptions)

Type declaration

    • Parameters

      Returns string

thumbnail

thumbnail: function

Formats an HTML image tag (<img>), and automatically uses the result object to query the REST API to get the thumbnail for this result. For example, this can be used to great effect when designing a template showing users or previews of files.

  • result: Optional. The current result object inside your template. In underscore, it is referenced as obj. By default, the result will be resolved automatically from your current template function ( Meaning the nearest result in the current call stack execution inside your template)
  • endpoint: Optional. The name of the endpoint to use for your thumbnail. Default is default.
  • options: Optional. The options to use (see IImageUtilsOptions).

Type declaration

time

time: function

Formats a date value to a time-only string using the specified options.

  • content: The Date value to format.
  • options: Optional. The options to use (see IDateToStringOptions).

Type declaration

timeSpan

timeSpan: function

Given a number, either in millisecond or second, convert to a HH:MM:SS format.

Examples

timeSpan(1, {isMilliseconds: false}) => '00:01'

timeSpan(1000, {isMilliseconds: true}) => '00:01'

Type declaration

translatedCaption

translatedCaption: function

Given a filetype value, try to return a translated and human readable version.

If the filetype is known and recognized by the framework, a translated value will be returned.

Examples

translatedCaption('doc') => Document

translatedCaption('xls') => Spreadsheet Document

  • value: The string value to translate

Type declaration

    • (value: string): string
    • Parameters

      • value: string

      Returns string

Hierarchy

  • ICoreHelpers