This example shows you how to create a slider template for a Smart Discovery.
Creating the template involves:
- Building a slider element for the discovery. The element code uses Mustache variables for dynamically populating the slider with Smart Discovery data.
- Fetching the Smart Discovery data for the page the visitor is currently viewing. You use the Smart Discovery API for fetching the data.
- Defining content options for setting the display title and page type of the discovery.
You create the template in the Frosmo Control Panel.
The following figure shows an example of the final discovery slider on a category page.
Figure: Smart Discovery slider on a category page
This example assumes that Frosmo Search & Smart Discovery is correctly set up on the site, and that the platform has generated the Smart Discovery data for categories.
If you're trying out this example on a production site, but do not want the example to interfere with production content, use a workspace.
To create the Smart Discovery slider template:
- In the Frosmo Control Panel, in the sidebar, select Modifications.
- Select the Templates tab.
- Click Create template.
Define the following settings:
- Name: Enter "Smart Discovery slider".
- Export content: Leave this field to Automatic.
- Minified: Leave this field to Enabled.
Content: Enter the following content for the template.
The content defines the HTML and CSS code for the slider. The HTML includes multiple Mustache tags, which need to be replaced with specific values in the final rendered content. The content also defines some JavaScript for handling the slider controls.
Feel free to edit the content to adapt the slider to your site's layout, style, and functionality.
Content prerenderer: Enter the following content prerenderer for the template.
The content prerenderer:
- Fetches the Smart Discovery data by calling the Smart Discovery API.
- Builds the final content options with which to render the template content. These are the values for the Mustache tags in the content. The values include the Smart Discovery title, which comes from the
title
content option set in the modification variation, and the details of the Smart Discovery suggestions, which the prerenderer extracts from the Smart Discovery data. - Renders the template content with the final content options. The prerenderer uses the
facets
of a suggestion to build the search query URL for the suggestion.
This example was designed to work on the Frosmo retail demo site. When trying out the example on your own site, check and update at least the prerenderer code tagged with a
@todo
comment.Content options schema: Enter the following content options schema for the template.
The schema describes the following content options, which must be set in the content options UI of the modification variation:
- Smart Discovery title (
title
) - Smart Discovery page type (
pageType
)
The template uses the content options to create the final slider element.
- Smart Discovery title (
Content options UI schema: To further customize the content options UI, enter the following content options UI schema for the template.
The UI schema defines placeholder texts for the Smart Discovery title and Smart Discovery page type fields.
The following figure shows the complete template in the Control Panel. Click the figure to view a larger version.
For more information about the settings, see Creating and editing a template.
Use the content options UI preview at the bottom of the editor to test that the content options schema and content options UI schema are correctly defined.
The preview is fully interactive, so any changes you make to the schemas are automatically reflected in the preview. You can also set the content option in the preview as you would in the actual content options UI, and you can see a preview of the JSON object generated based on the set value.
The following figure shows the content options UI preview for template.
- Click Save.
You have created the template. You can now use the template in a modification to create a Smart Discovery slider for the site.
For a practical example where you can use the template, see Example: Creating a Smart Discovery for category pages.