Documentation Index
Fetch the complete documentation index at: https://docs.uselayers.com/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This is the SDK equivalent of Rendering sort orders in Liquid. You still render the dropdown from sort metaobjects in Liquid — that’s the only way to keep the UI in sync with the dashboard — but you pass the selectedcode to the SDK’s client.collection() or client.search() controller as sort instead of issuing the API request yourself.
Use this version when you’ve already installed @commerce-blocks/sdk in your theme. For a no-dependencies version, see the Liquid + Fetch guide.
Prerequisites
- Sort orders configured in the Layers dashboard with Enable as Storefront Sort turned on.
- The SDK installed and a client created in your theme — see SDK installation. Mirror the dashboard sort orders into the
sortsconfig (the snippet in Rendering facets with the SDK generates it from metaobjects).
Collection sort dropdown
Render the dropdown from sort metaobjects
Filter by the
collection scope and order by the configured order field. Read the collection’s default sort from layers.default_sort_order and the active sort from the URL.Drive a collection controller from the dropdown
Create the controller once, subscribe to render, and call Passing
execute({ sort }) whenever the selection changes. The SDK dedupes against in-flight requests and updates the state signal — subscribers re-render automatically.defaultSort on the controller tells the SDK which code to use when execute() is called with no sort. Pass sort: undefined to fall back to that default.Search sort dropdown
The pattern is identical — filter the metaobjects by thesearch scope and drive a client.search() controller instead.
Combining sort with filters and pagination
Controller options merge acrossexecute() calls. Passing only the field you want to change keeps the rest sticky.
color) resolve to API codes (options.color) without extra wiring.
Default sort orders
| Surface | Default source |
|---|---|
| Collection | defaultSort on the controller (or the controller’s first call) → falls back to the collection’s layers.default_sort_order metafield → falls back to the store default |
| Search | Relevance |
defaultSort so the SDK and the rendered dropdown agree on the default.
Why the SDK over Fetch
| Concern | Fetch version | SDK version |
|---|---|---|
| Driving the request | Hand-rolled fetch to /browse or /search | controller.execute({ sort }) |
| Re-renders | DIY DOM updates | Signal subscriber |
| Sticky options | Track manually | Merged automatically across calls |
| Caching across nav | DIY | Restored from localStorage |
Troubleshooting
Selecting a sort doesn’t change the grid. Confirm the subscriber renders on everydata change, not just the first one. The signal emits a new state on every execute().
The wrong default is pre-selected. Read request.params.sort and the layers.default_sort_order metafield in Liquid, mark the matching <option> as selected server-side, and pass the same code as defaultSort to the controller.
Sort options are missing from the dropdown. Check Enable as Storefront Sort is on in the Layers dashboard, the metaobject’s scope array contains the right surface, and the same sort is listed in the SDK client’s sorts config.
See also
- Rendering sort orders in Liquid (Fetch) — the no-dependency equivalent
- Rendering facets with the SDK — companion guide for filter sidebars
- SDK installation —
sortsconfig and filter aliases - Client methods —
client.collection()andclient.search() - Sort orders — dashboard configuration