# 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
- currency
- date
- dateTime
- email
- emailDateTime
- encodeCarriageReturn
- fromFileTypeToIcon
- highlight
- highlightStreamHTML
- highlightStreamText
- image
- isMobileDevice
- loadTemplate
- number
- shorten
- shortenPath
- shortenUri
- size
- thumbnail
- time
- timeSpan
- translatedCaption

## Properties

### anchor

anchor: function

- Defined in ui/Templates/CoreHelpers.ts :219

Formats a clickable HTML link (`<a>`).

- `href`: The link URI
- `options`: Optional. The options to use (see IAnchorUtilsOptions)

#### Type declaration

- - (href: string, options?: IAnchorUtilsOptions): string

  - #### Parameters

    - ##### href: string

    - ##### Optional options: IAnchorUtilsOptions

    #### Returns string

### currency

currency: function

- Defined in ui/Templates/CoreHelpers.ts :179

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

- `content`: The number value to format.
- `options`: Optional. The options to use (see ICurrencyToStringOptions).

#### Type declaration

- - (content: any, options?: ICurrencyToStringOptions): string

  - #### Parameters

    - ##### content: any

    - ##### Optional options: ICurrencyToStringOptions

    #### Returns string

### date

date: function

- Defined in ui/Templates/CoreHelpers.ts :157

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

- - (content: any, options?: IDateToStringOptions): string

  - #### Parameters

    - ##### content: any

    - ##### Optional options: IDateToStringOptions

    #### Returns string

### dateTime

dateTime: function

- Defined in ui/Templates/CoreHelpers.ts :172

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

- - (content: any, options?: IDateToStringOptions): string

  - #### Parameters

    - ##### content: any

    - ##### Optional options: IDateToStringOptions

    #### Returns string

### email

email: function

- Defined in ui/Templates/CoreHelpers.ts :212

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

- Defined in ui/Templates/CoreHelpers.ts :187

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

- - (content: any, options?: IDateToStringOptions): string

  - #### Parameters

    - ##### content: any

    - ##### Optional options: IDateToStringOptions

    #### Returns string

### encodeCarriageReturn

encodeCarriageReturn: function

- Defined in ui/Templates/CoreHelpers.ts :333

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

- Defined in ui/Templates/CoreHelpers.ts :254

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

- - (result?: IQueryResult, options?: any): string

  - #### Parameters

    - ##### Optional result: IQueryResult

    - ##### Optional options: any

    #### Returns string

### highlight

highlight: function

- Defined in ui/Templates/CoreHelpers.ts :87

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

- Defined in ui/Templates/CoreHelpers.ts :130

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.

- `content`: The string content to highlight
- `termsToHighlight`: The terms to highlight (see IHighlightTerm)
- `phraseToHighlight`: The phrases to highlight (see IHighlightPhrase)
- `options`: Optional. The options defined below as IStreamHighlightOptions

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

- - (content: string, termsToHighlight: IHighlightTerm, phrasesToHighlight: IHighlightPhrase, options?: IStreamHighlightOptions): string

  - #### Parameters

    - ##### content: string

    - ##### termsToHighlight: IHighlightTerm

    - ##### phrasesToHighlight: IHighlightPhrase

    - ##### Optional options: IStreamHighlightOptions

    #### Returns string

### highlightStreamText

highlightStreamText: function

- Defined in ui/Templates/CoreHelpers.ts :107

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.

- `content`: The string content to highlight
- `termsToHighlight`: The terms to highlight (see IHighlightTerm)
- `phraseToHighlight`: The phrases to highlight (see IHighlightPhrase)
- `options`: Optional. The options defined below as IStreamHighlightOptions

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

- - (content: string, termsToHighlight: IHighlightTerm, phrasesToHighlight: IHighlightPhrase, options?: IStreamHighlightOptions): string

  - #### Parameters

    - ##### content: string

    - ##### termsToHighlight: IHighlightTerm

    - ##### phrasesToHighlight: IHighlightPhrase

    - ##### Optional options: IStreamHighlightOptions

    #### Returns string

### image

image: function

- Defined in ui/Templates/CoreHelpers.ts :226

Formats an HTML image tag (`<img>`).

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

#### Type declaration

- - (src: string, options?: IImageUtilsOptions): string

  - #### Parameters

    - ##### src: string

    - ##### Optional options: IImageUtilsOptions

    #### Returns string

### isMobileDevice

isMobileDevice: function

- Defined in ui/Templates/CoreHelpers.ts :341

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

- Defined in ui/Templates/CoreHelpers.ts :271

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

- Defined in ui/Templates/CoreHelpers.ts :150

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

- Defined in ui/Templates/CoreHelpers.ts :55

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

- Defined in ui/Templates/CoreHelpers.ts :67

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

- Defined in ui/Templates/CoreHelpers.ts :79

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

- Defined in ui/Templates/CoreHelpers.ts :313

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

- - (value: number, options?: ISizeOptions): string

  - #### Parameters

    - ##### value: number

    - ##### Optional options: ISizeOptions

    #### Returns string

### thumbnail

thumbnail: function

- Defined in ui/Templates/CoreHelpers.ts :241

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

- - (result?: IQueryResult, endpoint?: string, options?: IImageUtilsOptions): string

  - #### Parameters

    - ##### Optional result: IQueryResult

    - ##### Optional endpoint: string

    - ##### Optional options: IImageUtilsOptions

    #### Returns string

### time

time: function

- Defined in ui/Templates/CoreHelpers.ts :164

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

- - (content: any, options?: IDateToStringOptions): string

  - #### Parameters

    - ##### content: any

    - ##### Optional options: IDateToStringOptions

    #### Returns string

### timeSpan

timeSpan: function

- Defined in ui/Templates/CoreHelpers.ts :284

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'`

- `value`: The number to convert to a timespan
- `options` : The options to use (see ITimeSpanUtilsOptions)

#### Type declaration

- - (value: number, options: ITimeSpanUtilsOptions): string

  - #### Parameters

    - ##### value: number

    - ##### options: ITimeSpanUtilsOptions

    #### Returns string

### translatedCaption

translatedCaption: function

- Defined in ui/Templates/CoreHelpers.ts :327

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