Skip to content

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.

Search → Blocks → For developers, with the result template open and the preview beside it

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.

Templates use Mustache, the format most search layers use.

WriteWhat 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.

FieldWhat it holds
titleThe product name
title_htmlThe name with the matched words marked
priceThe price to pay, formatted in your currency: the sale price on a sale
regular_priceThe price before the sale, on a sale only
discountThe saving, such as −20%, on a sale only
on_saleTrue when the product is on sale
in_stock, out_of_stockTrue when the stock column says so
imageThe first photo
second_imageThe second photo when the image column holds a list, empty otherwise; the standard tile shows it on hover
urlThe product page
categoryThe last level of the first category
ratingThe rating
positionThe result’s place in the list, from 1
sale_badgeTrue when the product is on sale and in stock, as the widget’s own badge shows
add_to_cartTrue when the cart button shows: Add to cart button on Look → Results window, a price, in stock
Any columnEvery column of the collection by its name, such as {{brand}} or {{material}}

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:

ClassThe element
tm-item--tile, tm-item--rowThe result in a grid, and in a list
tm-item-media, tm-item-imgThe photo’s box and the photo
tm-item-img--hoverThe second photo, shown on hover
tm-item-tags, tm-item-tag--saleThe card’s badge corner and the sale badge
tm-item-bodyEverything beside or under the photo
tm-item-titleThe name. Matched words are in <mark>
tm-item-metaThe category under the name
tm-item-rating, tm-item-starsThe rating and its stars, lit by --tm-stars
tm-item-price-rowThe price line
tm-item-price, tm-item-price--saleThe price, and the price on a sale
tm-item-price-wasThe price before the sale
tm-item-cartThe cart button

A rule in Custom CSS such as .tm-item-title { font-size: 15px; } changes the built-in result and yours alike.

Add data-typemo-action to a button in a result template:

ValueWhat a click does
cartAdds the product to the cart, like the widget’s own cart button
similarShows 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.

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;
}
CaseBehaviour
<script>, on… attributes, javascript: linksRemoved 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
LengthUp to 10,000 characters per template
A field the collection doesn’t haveIt prints nothing
Class namesYours, or the result classes. Other widget classes change without notice
The standard result, unchangedNot saved: the shop keeps the widget’s own result and gets its fixes
Back to the standard resultClears 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.