Templates
For developers and agencies. The result template replaces what is inside every result with your own HTML. Open Search → Blocks, then For developers at the bottom, on Result: it opens with the widget’s own result as code; change it and it becomes yours. The preview shows it as you type. To add your own HTML above the results or on the start screen, use a Custom HTML block.
Templates hold HTML only. CSS has one place, Custom CSS beside Result: it styles the whole widget, your template included.
One template fills every list, so write it for both shapes: the result carries tm-item--tile in a
grid and tm-item--row in a list, and the result classes lay out the same markup
either way. The docs widget has no result template.
Syntax
Section titled “Syntax”Templates use Mustache, the format most search layers use.
| Write | What it does |
|---|---|
{{brand}} | Prints the field, with <, > and & shown as text |
{{{title_html}}} | Prints the title with the matched words in <mark>. Use three braces for it |
{{#on_sale}}…{{/on_sale}} | Shows the part when the field has a value; repeats it for each item of a list |
{{^in_stock}}…{{/in_stock}} | Shows the part when the field is empty or false |
Typing {{ in the editor lists the fields with a value from your first document. Insert field
finds one by name and puts it where the cursor is.
Result fields
Section titled “Result fields”| Field | What it holds |
|---|---|
title | The product name |
title_html | The name with the matched words marked |
price | The price to pay, formatted in your currency: the sale price on a sale |
regular_price | The price before the sale, on a sale only |
discount | The saving, such as −20%, on a sale only |
on_sale | True when the product is on sale |
in_stock, out_of_stock | True when the stock column says so |
image | The first photo |
second_image | The second photo when the image column holds a list, empty otherwise; the standard tile shows it on hover |
url | The product page |
category | The last level of the first category |
rating | The rating |
position | The result’s place in the list, from 1 |
sale_badge | True when the product is on sale and in stock, as the widget’s own badge shows |
add_to_cart | True when the cart button shows: Add to cart button on Look → Results window, a price, in stock |
| Any column | Every column of the collection by its name, such as {{brand}} or {{material}} |
Result classes
Section titled “Result classes”The standard result is written on the widget’s own classes, so the widget’s styles and your theme apply to it as to the built-in one, in a grid and in a list. These classes are as stable as the parts:
| Class | The element |
|---|---|
tm-item--tile, tm-item--row | The result in a grid, and in a list |
tm-item-media, tm-item-img | The photo’s box and the photo |
tm-item-img--hover | The second photo, shown on hover |
tm-item-tags, tm-item-tag--sale | The card’s badge corner and the sale badge |
tm-item-body | Everything beside or under the photo |
tm-item-title | The name. Matched words are in <mark> |
tm-item-meta | The category under the name |
tm-item-rating, tm-item-stars | The rating and its stars, lit by --tm-stars |
tm-item-price-row | The price line |
tm-item-price, tm-item-price--sale | The price, and the price on a sale |
tm-item-price-was | The price before the sale |
tm-item-cart | The cart button |
A rule in Custom CSS such as .tm-item-title { font-size: 15px; } changes the built-in result and
yours alike.
Actions
Section titled “Actions”Add data-typemo-action to a button in a result template:
| Value | What a click does |
|---|---|
cart | Adds the product to the cart, like the widget’s own cart button |
similar | Shows products like this one, on collections with semantic search |
A click anywhere else on the result opens the product, as before. The result is already a link, so a
template needs no <a> of its own. Similar shows on tiles only.
Example
Section titled “Example”A result with the brand above the name and a cart button. On Result:
<div class="my-card"> <img src="{{image}}" alt="" /> {{#brand}} <div class="my-card-brand">{{brand}}</div> {{/brand}} <div>{{{title_html}}}</div> <div class="my-card-price">{{price}}{{#on_sale}} <s>{{regular_price}}</s>{{/on_sale}}</div> {{#add_to_cart}}<button type="button" class="my-card-buy" data-typemo-action="cart"> Add to cart</button >{{/add_to_cart}}</div>On Custom CSS:
.my-card { display: flex; flex-direction: column; gap: 6px;}/* In a list the photo sits beside the text. */.tm-item--row .my-card { flex-direction: row; align-items: center;}.tm-item--row .my-card img { width: 56px;}.my-card-brand { font-size: 11px; text-transform: uppercase; opacity: 0.6;}.my-card-price { font-weight: 700;}.my-card-buy { border: 0; border-radius: 999px; padding: 6px 12px; background: #1f4d3a; color: #fff;}| Case | Behaviour |
|---|---|
<script>, on… attributes, javascript: links | Removed before the template reaches the page, in Custom HTML blocks too |
A template that does not parse, or a <style> | It can’t be saved: the field names the error. CSS goes in Custom CSS |
| Length | Up to 10,000 characters per template |
| A field the collection doesn’t have | It prints nothing |
| Class names | Yours, or the result classes. Other widget classes change without notice |
| The standard result, unchanged | Not saved: the shop keeps the widget’s own result and gets its fixes |
| Back to the standard result | Clears your template: the widget’s own result comes back |
Next: Blocks for rows and your own HTML around the results, Theming with CSS for colours, parts and Custom CSS, or Look and branding for the rest of the form.