The Recommendations Item component displays information for an individual product or page.

Tag

The tag for this component is <hawksearch-recommendations-item>.

*Note: This component should only be used within the context of the Recommendations component.

Event-Binding Attributes

Name Value
hawksearch-image

Image elements with this attribute will have their src value replaced with a placeholder image URL if the image fails to load.

Name Value
hawksearch-link

Anchor elements with this attribute will be tracked when clicked.

Default Template

The following is the default Handlebars template for this component. To create a custom template, it is recommended to use this as a starting point.

<div class="recommendations__item">
{{#if pinned}}
<span class="recommendations__item__pin">
<hawksearch-icon name="star"></hawksearch-icon>
</span>
{{/if}}
{{#if (lt salePrice price)}}
<span class="recommendations__item__sale-indicator">{{strings.sale}}</span>
{{/if}}
<a hawksearch-link href="{{url}}" class="recommendations__item__image" aria-label="{{title}}">
<img hawksearch-image src="{{imageUrl}}" alt="" />
</a>
<div class="recommendations__item__title">
<a hawksearch-link href="{{url}}">{{title}}</a>
</div>
{{#if rating}}
<hawksearch-rating rating="{{rating}}"></hawksearch-rating>
{{/if}}
{{#unless (eq price undefined)}}
<div class="recommendations__item__price" itemprop="offers" itemtype="http://schema.org/Offer" itemscope>
{{#if (lt salePrice price)}}
<span class="recommendations__item__price__original">{{currency price}}</span>
<span class="recommendations__item__price__current" itemprop="price">{{currency salePrice}}</span>
{{else}}
<span class="recommendations__item__price-__current" itemprop="price">{{currency price}}</span>
{{/if}}
</div>
{{/unless}}
<hawksearch-variant-selector></hawksearch-variant-selector>
</div>

Hierarchy

Properties

bindFromEvent: boolean = false
componentName: keyof HawkSearchComponents = 'recommendations-item'

Optional instance-level configuration to override the global configuration

The data bound to the Handlebars template.

The data bound to the component.

defaultHtml: string = defaultHtml
handlebars: typeof Handlebars = HawkSearch.handlebars

The Handlebars reference shared by all HawkSearch components.

Accessors

  • get configuration(): undefined | TConfig
  • The optional configuration object for this component.

    Returns undefined | TConfig

  • get rootElement(): ParentNode
  • The root element which should be used for querying any child elements. This resolves to this.shadowRoot if the Shadow DOM is enabled, otherwise this.

    Returns ParentNode

Methods

  • After the component is rendered, this method is called to bind any child components.

    Returns void

  • Replaces placeholders in a given string with values from a data object.

    Parameters

    • template: string

      The template string.

    • values: Record<string, string>

      The object containing properties which will be bound to template.

    Returns string

    The template string with all placeholders replaced by the values specified in values.

  • After the component is rendered, this method is called for any additional processing (such as attaching event listeners) which needs to occur.

    Returns void

  • Optional method that can be overwritten to register Handlebars helper functions which can be accessed from the template. For more information, see Custom Helpers.

    Returns void

  • Determines whether the data meets the necessary conditions to perform data binding and render content.

    Returns boolean

    Whether the component should be rendered. If false, the component will have empty contents and be set to display: none;.

  • Type Parameters

    • T

    Parameters

    • name: string
    • data: T

    Returns void