Build a Shopify theme from scratch, with Liquid · Part 5 of 6
Search, pagination, metafields, translations and customers
Predictive search through a fetched section, a search page with type chips, pagination as one snippet from paginate.parts, the product page reading saanjh.* metafields, the theme in Hindi with a language selector, and what new customer accounts mean for a theme.
By Abhishek Fouzdar
The storefront has the pages a buyer sees most. This part fills in the ones they reach from the header and the footer: search, with suggestions as they type; the search results page with its types; pagination done once as a snippet and used everywhere; the product page reading the store's metafields; the theme in a second language, with a selector; and what customer accounts mean for a theme in 2026. Part 4 built the variant picker, the Cart API and the drawer.

Predictive search
Shopify's predictive search endpoint is /search/suggest, and like everything in part 4 it can render a section instead of JSON. The theme adds a section that exists only for that purpose:
{%- comment -%} sections/predictive-search.liquid {%- endcomment -%}
{%- liquid
assign products = predictive_search.resources.products
assign collections = predictive_search.resources.collections
assign articles = predictive_search.resources.articles
assign terms = predictive_search.terms | escape
-%}
{%- if predictive_search.performed -%}
{%- if products.size == 0 and collections.size == 0 and articles.size == 0 -%}
<p class="text-ink-2 py-2">{{ 'general.search.no_results' | t: terms: terms }}</p>
{%- else -%}
<div class="grid gap-8 md:grid-cols-[3fr_1fr]">
{%- if products.size > 0 -%}
<div>
<p class="eyebrow mb-3">{{ 'general.search.types.product' | t }}</p>
<ul class="grid grid-cols-2 md:grid-cols-4 gap-4" role="list">
{%- for product in products -%}<li>{% render 'product-card', product: product %}</li>{%- endfor -%}
</ul>
</div>
{%- endif -%}
<div class="flex flex-col gap-6">
...collections and articles as lists...
<a href="{{ routes.search_url }}?q={{ predictive_search.terms | url_encode }}&options[prefix]=last">{{ 'general.search.see_all' | t: terms: terms }}</a>
</div>
</div>
{%- endif -%}
{%- endif -%}
{% schema %}
{ "name": "t:sections.predictive_search.name", "settings": [] }
{% endschema %}
predictive_search is an object that exists only on the suggest route, so this section is never placed in a template; it is fetched. The products in resources.products are full product objects, which is why part 2's card renders them unchanged. The header gets a <predictive-search> element around the search icon: the icon stays a link to the search page, and a <dialog> holding a real search form and an empty results container:
<predictive-search data-url="{{ routes.predictive_search_url }}">
<a href="{{ routes.search_url }}" class="icon-btn" data-search-open aria-label="{{ 'general.search.search' | t }}">{% render 'icon', name: 'search' %}</a>
<dialog id="SearchDialog" class="fixed inset-x-0 top-0 bottom-auto m-0 w-full max-w-none max-h-[90dvh] overflow-y-auto bg-ground p-0 shadow-xl backdrop:bg-ink/40" aria-label="{{ 'general.search.search' | t }}">
<div class="wrap py-6 flex flex-col gap-5">
<form action="{{ routes.search_url }}" method="get" role="search" class="flex gap-3">
<label for="SearchInput" class="sr-only">{{ 'general.search.search' | t }}</label>
<input id="SearchInput" type="search" name="q" autocomplete="off" placeholder="{{ 'general.search.placeholder' | t }}" aria-controls="PredictiveResults" aria-expanded="false">
<input type="hidden" name="options[prefix]" value="last">
<button type="submit" class="btn">{{ 'general.search.search' | t }}</button>
<button type="button" class="icon-btn" data-search-close aria-label="{{ 'accessibility.close' | t }}">{% render 'icon', name: 'close' %}</button>
</form>
<div id="PredictiveResults" aria-live="polite"></div>
</div>
</dialog>
</predictive-search>
The script debounces typing, cancels the previous request with an AbortController when a new one starts, and drops the fetched section into the container:
async search() {
const q = this.input.value.trim();
this.controller?.abort();
if (q.length < 2) { this.results.replaceChildren(); return; }
this.controller = new AbortController();
const url = `${this.dataset.url}?q=${encodeURIComponent(q)}§ion_id=predictive-search&resources[type]=product,collection,article&resources[limit]=4&resources[options][unavailable_products]=last`;
try {
const html = await (await fetch(url, { signal: this.controller.signal })).text();
const section = parse(html).querySelector('#shopify-section-predictive-search');
this.results.replaceChildren(...section.children);
this.input.setAttribute('aria-expanded', 'true');
} catch (error) {
if (error.name !== 'AbortError') throw error;
}
}
resources[type] picks which objects to search, resources[limit] is per type, and unavailable_products=last keeps sold-out products in the results but at the end. Pressing Enter submits the form to the search page as it always would; the suggestions are a shortcut, not the search.
The search page
search is the object on /search: terms, performed, results, results_count, and types, the object types that were searched. By default that is products, articles and pages; a type parameter narrows it, and the results page turns that into chips:
{%- liquid
assign q = search.terms | url_encode
assign only = ''
if search.types.size == 1
assign only = search.types.first
endif
-%}
<div class="flex flex-wrap items-center gap-2" role="group" aria-label="{{ 'general.search.types.label' | t }}">
{%- assign chips = 'all,product,article,page' | split: ',' -%}
{%- for chip in chips -%}
{%- liquid
if chip == 'all'
assign href = routes.search_url | append: '?q=' | append: q | append: '&options[prefix]=last'
else
assign href = routes.search_url | append: '?q=' | append: q | append: '&options[prefix]=last&type=' | append: chip
endif
...active when `only` matches, label from a case on chip...
-%}
<a href="{{ href }}" class="..." {% if active %}aria-current="true"{% endif %}>{{ label }}</a>
{%- endfor -%}
</div>
The results are one list of mixed objects, and item.object_type says what each is, so the loop is a case: products get the card, articles get their image and date, pages get a text tile. options[prefix]=last makes the search match word prefixes, so "bras" finds the brass pieces; it is sent as a hidden field by every search form in the theme.

There is one thing a search page cannot do from Liquid alone, and that is filtering by price, availability or metafield. Filters come from the Search & Discovery app and appear on collection.filters and search.filters once the merchant has configured them; this store has none, so the theme renders none, and a filter sidebar is the obvious next feature for whoever picks the theme up.
Pagination, once
Three pages paginate: collections, search and the blog. The markup was copied twice by part 2 and is now a snippet:
{%- comment -%} {% render 'pagination', paginate: paginate %} inside a {% paginate %} block {%- endcomment -%}
{%- if paginate.pages > 1 -%}
<nav class="flex justify-center items-center gap-1 pt-4" aria-label="{{ 'general.pagination.label' | t }}">
{%- if paginate.previous -%}
<a href="{{ paginate.previous.url }}" rel="prev" class="icon-btn" aria-label="{{ 'general.pagination.previous' | t }}"><span class="rotate-180 inline-flex">{% render 'icon', name: 'arrow' %}</span></a>
{%- endif -%}
{%- for part in paginate.parts -%}
{%- if part.is_link -%}
<a href="{{ part.url }}" class="..." aria-label="{{ 'general.pagination.page' | t: page: part.title }}">{{ part.title }}</a>
{%- elsif part.title == paginate.current_page -%}
<span aria-current="page" class="...">{{ part.title }}</span>
{%- else -%}
<span class="..." aria-hidden="true">{{ part.title }}</span>
{%- endif -%}
{%- endfor -%}
{%- if paginate.next -%}
<a href="{{ paginate.next.url }}" rel="next" class="icon-btn" aria-label="{{ 'general.pagination.next' | t }}">{% render 'icon', name: 'arrow' %}</a>
{%- endif -%}
</nav>
{%- endif -%}
paginate is only defined inside a {% paginate %} block, and a snippet does not inherit the caller's variables, so it is passed in explicitly. paginate.parts is already the list a pagination control needs: numbered links, the current page as a non-link, and "…" where pages are skipped; previous and next are separate so they can carry rel. The Handcrafted collection, forty products at twelve a page:

Shopify also has a default_pagination filter that outputs a whole control in one call. It is fine for a first draft and wrong for a designed theme, because its markup is its own.
Metafields
The store's products carry a set of saanjh.* metafields from the catalogue import: material, weave, craft, origin, series, a multi-line care note and a JSON list of measurements. A metafield in Liquid is product.metafields.<namespace>.<key>, an object with type and value; value is a string for the text types and already-parsed data for json. The product page gets two accordions from them:
{%- liquid
assign specs = product.metafields.saanjh
assign spec_keys = 'material,weave,craft,origin,series' | split: ','
assign has_specs = false
for key in spec_keys
assign v = specs[key].value
if v != blank and v != '—'
assign has_specs = true
endif
endfor
if specs.measurements.value.size > 0
assign has_specs = true
endif
-%}
{%- if has_specs -%}
<details class="border-t border-line group">
<summary>{{ 'products.product.specifications' | t }}</summary>
<dl class="grid grid-cols-[auto_1fr] gap-x-8 gap-y-2 text-sm pb-4">
{%- for key in spec_keys -%}
{%- assign v = specs[key].value -%}
{%- if v != blank and v != '—' -%}
<dt class="text-ink-2">{{ label }}</dt><dd>{{ v }}</dd>
{%- endif -%}
{%- endfor -%}
{%- for row in specs.measurements.value -%}
<dt class="text-ink-2">{% if forloop.first %}{{ 'products.product.measurements' | t }}{% endif %}</dt><dd>{{ row.name }} · {{ row.value }}</dd>
{%- endfor -%}
</dl>
</details>
{%- endif -%}
{%- if specs.care != blank -%}
<details class="border-t border-line group">
<summary>{{ 'products.product.care' | t }}</summary>
<div class="text-sm text-ink-2 pb-4 leading-relaxed">{{ specs.care | metafield_tag }}</div>
</details>
{%- endif -%}
specs[key] is dynamic property access on the namespace, which lets the five keys be a list. The import wrote "—" into fields that do not apply, like the weave of a brass lantern, so the theme treats that as empty. metafield_tag renders a metafield as HTML suited to its type, here a <span> with the line breaks of the multi-line text kept; for the plain values {{ v }} is enough, and for the JSON list the loop reads row.name and row.value straight from the parsed data.

The labels are translation keys, which caught a Theme Check rule worth knowing. The first draft built them with 'products.specs.' | append: key | t, and Theme Check reported 'products.specs.' does not have a matching entry in 'locales/en.default.json': it verifies the literal it can see, and a key assembled at runtime is invisible to it. A case over the five keys, each one literal, passes the check and gets checked. That is the better trade.
A second language
Every string in the theme has gone through t since part 1, reading locales/en.default.json. A second language is a second file with the same keys, locales/hi.json, and a store that has the language published. The file is sixty-odd lines of Hindi; the shape is the point:
{
"cart": {
"general": {
"title": "आपकी कार्ट",
"item_count": { "one": "{{ count }} वस्तु", "other": "{{ count }} वस्तुएँ" },
"added": "कार्ट में जोड़ा गया: {{ title }}"
}
}
}
Plural forms are one and other keys chosen by the count argument, and {{ count }} and {{ title }} are interpolated by t. A missing key does not fall back to English; it renders as "Translation missing: hi.cart.general.title", so the theme's build checks that the two files have the same key set before pushing, which is a three-line script and the reason the Hindi file is complete.
A store publishes a language in Settings → Languages, and it has to be attached to the domain, which is a Markets setting; for this store that was two Admin API calls, shopLocaleEnable and webPresenceUpdate with alternateLocales: ["hi"], after which /hi/ is a root URL. The footer gets a selector when there is more than one language to choose from:
{%- if localization.available_languages.size > 1 -%}
{%- form 'localization', id: 'LocalizationForm', class: 'flex items-center gap-2' -%}
<label for="LocaleSelect" class="sr-only">{{ 'general.language.label' | t }}</label>
<select id="LocaleSelect" name="locale_code" data-localization-select>
{%- for language in localization.available_languages -%}
<option value="{{ language.iso_code }}" lang="{{ language.iso_code }}" {% if language.iso_code == localization.language.iso_code %}selected{% endif %}>{{ language.endonym_name | capitalize }}</option>
{%- endfor -%}
</select>
<noscript><button type="submit" class="btn btn-ghost">{{ 'general.language.apply' | t }}</button></noscript>
{%- endform -%}
{%- endif -%}
{% form 'localization' %} posts to /localization, Shopify sets the language and redirects back to the same page under the other prefix; the two-line script submits the form when the select changes. The product page in Hindi:

Everything the theme says is translated; everything the merchant wrote is not, because the product title, options and description are store content and are translated separately, through the Translate & Adapt app or the translations API. Dates follow the language with no work: the blog's date: format: 'date' renders "April 6, 2026" in English and "6 अप्रैल 2026" in Hindi, because the named formats are Shopify's, per locale, and the theme has stopped writing %-d %B %Y.
The editor has a translation layer of its own: locales/en.default.schema.json holds the strings that section schemas reference as "name": "t:sections.predictive_search.name", so merchant-facing labels can be translated without touching Liquid. The new section uses it; the older sections keep their literal labels, and converting them is a mechanical afternoon rather than a design question.
Customers
This store uses new customer accounts, which is the default for new stores: login and the account pages are hosted by Shopify at shopify.com/<id>/account, with a one-time code instead of a password, and the theme has no templates for them. The header's account icon links to routes.account_url, which redirects there, and when a customer is signed in the customer object exists on every page:
{%- liquid
if customer
assign account_label = 'customer.account.greeting' | t: name: customer.first_name
else
assign account_label = 'customer.account.title' | t
endif
-%}
<a href="{{ routes.account_url }}" class="icon-btn" aria-label="{{ account_label }}" title="{{ account_label }}">{% render 'icon', name: 'account' %}</a>
The other kind, classic accounts, is what older themes were built for: the theme owns templates/customers/login, register, account, order, addresses, activate_account and reset_password, each with a {% form %} of its own, and the Shopify CLI's theme generator still scaffolds them. A theme meant for both kinds ships those templates; one built today for a store on new accounts can leave them out, as this one does, and shop.customer_accounts_enabled is the flag that hides the icon when accounts are off entirely.
shopify theme check
53 files inspected with no offenses found.
What went wrong
Hindi was published and still not offered. shopLocaleEnable plus published: true made the language exist, and localization.available_languages kept returning one entry, so the footer rendered no selector. A language is per domain: the store's web presence had alternateLocales: [] until webPresenceUpdate added hi, and only then did /hi/ route and the selector appear. In the admin this is the Markets page, not the Languages page, which is where I had been looking.
Devanagari in the wrong face. Inter and Manrope have no Devanagari glyphs, so the Hindi strings fall through to the fallback_families the font object provides, which is sans-serif. It reads fine; it is not the brand's face. A theme that targets a script its fonts do not cover picks a second font for it, and the font picker's library has several.
Theme Check and dynamic translation keys, above. The fix was less clever code.
Part 6 is the last: performance, measured on Lighthouse; accessibility beyond what the markup has done so far; Theme Check's stricter rules; and publishing, which for a theme means a zip the merchant uploads, a theme push --publish, or a Theme Store submission with its own review.
New posts by email
Get new posts by email. Nothing else, no digests, unsubscribe in one click.
Comments
Comments are GitHub Discussions in shipbytes/discussions. Sign in with GitHub to post.
In this series
5 / 6- OverviewBuild a Shopify theme from scratch, with Liquid
- Part 1The anatomy of a theme, and one that renders
- Part 2Liquid on the product and collection pages
- Part 3Sections, blocks and the theme editor
- Part 4Variants without reloads, the Cart API and a cart drawer
- Part 5Search, pagination, metafields, translations and customers
- Part 6Performance, accessibility, Theme Check and publishing