Template Engine
All {{data-bindings}} used in FactFinder Web Components refer to the underlying JSON response returned by FactFinder.
You can inspect the response data by opening your browser's Dev Tools (press F12 key) and navigating to the Network tab. Filter by Fetch/XHR to find relevant requests more easily. Requests to FactFinder and their response data will appear here.
Elements with a visual component (and a few others) pick the relevant portion of this data for rendering. For example, the ff-record-list element takes the hits list from a search result and renders ff-record elements each supplied with one item from the hits list. The ff-asn element takes the list of facets and generates its child elements from it.
Danger of Cross Site Scripting (XSS)
The template engine HTML-escapes the content of data bindings. If you want the data to be interpreted as HTML, use triple curly braces like {{{data-binding}}}.
Data Binding Example
By expanding the hits array and one of its items in a search response, we can take a look at the fields returned by FactFinder. The hits array holds a collection of SearchRecord objects. (Note that this is the name defined by the FactFinder API. It does not appear in the response data.) This is the product data.
All fields returned in these objects' masterValues and variantValues are imported from your data feed. The fields to be returned can be configured in the FactFinder UI.
Consider the following data-binding example to see how to access the data.
<ff-record-list>
<template data-role="record">
<ff-record>
<div>Title: {{variantValues.0.Title}}</div>
<div>position: {{position}}</div>
</ff-record>
</template>
</ff-record-list>Underlying Template Engine
FactFinder Web Components uses handlebars as the engine to resolve its HTML templates. Please refer to the official documentation for available features and their usage:
For example, you can render parts of your template conditionally by using this syntax:
In the example above, only when variantValues.0.Discount_Percent holds a truthy value will the contained div with "Special discount" be rendered.
As handlebars does not offer logic in templates, your data must adhere to a certain format in some situations. If the data to be displayed is not provided in the required format, use the Transform API to modify it accordingly.
Clashes with third party frameworks' data binding
Most front-end frameworks provide their own data binding syntax. As it stands, {{ }} seems to be the most popular choice for these data bindings.
This often leads to conflicts when you are embedding FactFinder Web Components in third party frameworks. Typically, your framework resolves all data bindings before the resulting HTML is accessible to Web Components.
To prevent such conflicts your framework might offer a way to render parts of your template verbatim.
An example with JSX syntax:
Another method that can provide a viable solution is to define custom delimiters to be used by Web Components' template engine. You can do so by setting the dataBindingTags in the Configuration. For example:
This allows you to define your HTML templates like this:
Last updated
Was this helpful?