Support Menu

Interface ICoreHelpers

The core template helpers provided by default.

Example usage:

HTML

<div class="CoveoFieldValue" data-helper="helperName" data-helper-options-optionName="option-value"></div>

Underscore

<%= helperName(argument1, argument2) %>

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.

  • value: The number value to format.
  • options: The options to use (see ICurrencyToStringOptions).

Type declaration

    • (content: any, options?: ICurrencyToStringOptions): string
    • Parameters

      • content: any
      • Optional options: ICurrencyToStringOptions

      Returns string

date

date: function

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

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

Type declaration

    • (content: any, options?: IDateToStringOptions): string
    • Parameters

      • content: any
      • Optional options: IDateToStringOptions

      Returns string

dateTime

dateTime: function

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

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

Type declaration

    • (content: any, options?: IDateToStringOptions): string
    • Parameters

      • content: any
      • Optional options: IDateToStringOptions

      Returns string

email

email: function

Renders one or several email values in mailto: hyperlinks.

  • value: The string or array of string that contains a list of semicolon-separated email values. When multiple values are passed, each value is displayed in a separate hyperlink.
  • companyDomain: 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: 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: 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: 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

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

Type declaration

    • (content: any, options?: IDateToStringOptions): string
    • Parameters

      • content: any
      • Optional options: IDateToStringOptions

      Returns string

encodeCarriageReturn

encodeCarriageReturn: function

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

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: The current result object inside your template. In underscore, it is referenced as obj. Optional, 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: The options to use (see IIconOptions).

Type declaration

highlight

highlight: function

Highlights a string using the provided highlight information.

  • highlights: 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.

Type declaration

highlightStreamText

highlightStreamText: function

This helper 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.

Type declaration

image

image: function

Formats an HTML image tag (<img>).

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: 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: 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.

  • value: The numeric value to format.
  • format: The format string to use. The options available are defined by the Globalize library.

Type declaration

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

      • content: string
      • format: string

      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.

  • value: 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.

  • value: 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.

  • value: 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

Given a number, which represent a file size in bytes, format the value into a logical unit size.

eg:

size(1024) => 1024 B

size(1025) => 1 KB

size(10240) => 10 KB

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 preview of files.

  • result: The current result object inside your template. In underscore, it is referenced as obj. Optional, 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: The options to use (see IImageUtilsOptions).

Type declaration

time

time: function

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

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

Type declaration

    • (content: any, options?: IDateToStringOptions): string
    • Parameters

      • content: any
      • Optional options: IDateToStringOptions

      Returns string

timeSpan

timeSpan: function

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

eg:

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.

eg:

translatedCaption('doc') => Document

translatedCaption('xls') => Spreadsheet Document

Type declaration

    • (value: string): string
    • Parameters

      • value: string

      Returns string

Hierarchy

  • ICoreHelpers