MobiariDocs

Themes and the storefront SDK

What the platform gives every Liquid theme, and the SDK for themes and headless stores.

A theme owns the look of a store. The platform owns the behaviour that has to be the same everywhere: validation of Brazilian data, forms, the customer account and its session. Themes use those pieces instead of rewriting them, so a fix reaches every store at once.

What every page gets

Every page, in the layout, templates and sections alike, receives shop, request, routes, cart, customer (when someone is signed in), template, settings, locale, discounts, cms, forms, brand, menus, canonical_url, and portal on the account pages. Each page type adds its own subject: product on a product page, collection on a category, search on the search page, order on the confirmation page, and so on.

The Theme reference lists the page types with their addresses, and every object with every field: its type, whether it may be absent or nil, and what it means. It is generated from the platform code, so it is exact. To look at an object while you build, print it with the json filter, as in {{ product | json }} (debugging).

Structured data

The platform adds schema.org JSON-LD to the <head> of every theme's pages: Organization (the store's name, home page and logo: the header's image, else the brand's) and WebSite with a SearchAction on the store search on the home page, and a BreadcrumbList on product pages (Início / Produtos / product) and category pages (Início / Categorias / category). A page that already prints a block of one of these types keeps its own: a Store or a LocalBusiness counts as the Organization. The product's Product (or ProductGroup, one Product per variant) comes from the platform's product section. Stores have one language, so pages carry no hreflang.

Sections

Pages are made of sections, like Shopify's Online Store 2.0. A JSON template lists them and their order, and the layout places section groups:

templates/index.json
{
  "sections": {
    "hero": { "type": "slideshow", "settings": { "source": "cms", "cms_collection": "hero-videos" } },
    "news": { "type": "featured-collection", "settings": { "heading": "Novidades", "card_badge": "Novo" } }
  },
  "order": ["hero", "news"]
}
layout/theme.liquid
{% sections 'header-group' %}
<main>{{ content_for_layout }}</main>
{% sections 'footer-group' %}

sections/header-group.json and sections/footer-group.json have the same shape as a template. The platform ships the sections, so a theme only chooses, orders and styles them:

SectionWhat it is
headerLogo (image or text), menu links, secondary links in the mobile menu, search, account and cart.
footerLogo, a sign-up form, columns of links, contact lines with icons, payment logos.
announcement-bar, image-banner, rich-text, image-with-text, video, collapsible-content, formContent blocks.
slideshowImages and videos, per device, from blocks or from a CMS collection (asset, poster, viewport, link).
featured-collectionProducts: the newest, all, or one collection, through the platform's product card.
collection-listCategory cards, name below or over the image.
multicolumnColumns with an icon or image, title and text ([pix] becomes the store's PIX discount).
whatsapp-buttonThe floating WhatsApp button.
popupPlaces the store's popups (Grow > Popups) and sets their look; the popup script loads after the page.

Product grids use {% render 'mobiari-product-card', product: product %} (optional badge: and button:). It shows the price the customer pays (the promotional compare_at_price when set), the struck price, installments (card_installments in the theme settings), the PIX price and the "Esgotado" badge. Every amount is <span class="mb-price" data-cents="...">.

Restyle everything through the --mb-* custom properties and the mb-* classes; the platform's base CSS loads first, so the theme's rules win. A theme file with the same name, sections/<type>.liquid with its own {% schema %}, replaces a platform section, and a section of the theme's own works the same way. Publishing refuses a page that names a section or block type that does not exist.

Forms

Forms are built in the admin (Loja online > Formulários): typed fields (text, e-mail, phone, CPF, CNPJ, CPF or CNPJ, CEP, number, date, choices, consent), notification e-mails and customer tags. Put one on a page with the built-in snippet:

{% render 'mobiari-form', form: forms.contato %}

It renders a plain HTML form that works without JavaScript. The SDK upgrades it: masks as the visitor types, the server's rules before sending, field errors from the server, Cloudflare Turnstile when the platform has it, and mobiari:submitted / mobiari:error events. The server validates and stores every value in canonical form (digits, E.164 phone), completes the customer by e-mail and notifies the store.

Style it with the mobiari-form, mobiari-field, mobiari-field__label, mobiari-field__input, mobiari-field__error and mobiari-form__submit classes, or ship your own snippets/mobiari-form.liquid keeping the same names, name attributes and data-* attributes.

Tags and filters from Shopify themes

Besides Liquid's standard tags and filters, the platform takes the pieces a Shopify-style theme reaches for, mapped to its own:

  • {% form 'type', object, class: '...' %}...{% endform %} writes a <form> with Shopify's hidden form_type and utf8 inputs and every named argument as an attribute. product adds to the cart (a plain post with id and quantity works without JavaScript and opens the cart); cart opens the cart page, where checkout runs; contact and customer (a newsletter) post to a store form: the one you pass (forms.contato or its slug), else the form with slug contato or newsletter, and contact[email] field names reach its email field; customer_login, create_customer, recover_customer_password and guest_login open the sign-in page (they post, and what was typed is dropped, so a password field never reaches an address: customers sign in with an e-mail code there). Inside, form.errors is nil. Any other type fails when the theme is checked. Liquid here has no ? in names, so write form.posted_successfully checks as a script that reads the #form-enviado anchor the store form returns to.
  • {% paginate list by 12 %}...{% endpaginate %}: inside, the list holds the current page and paginate describes the pages. On a category, a taxonomy term or all products the server pages the list (filters and order kept in the addresses), and a number after by is the page size; on the search page it is the server's page of search.results; any other list (CMS entries, a section's products) is paged with ?pagina=N.
  • {{ paginate | default_pagination }} writes the page links (prev, page, current, deco and next spans); previous: and next: change the arrows' words.
  • {{ image | image_url: width: 600 }} gives the URL of the library rendition that covers the size (height: too, format: 'jpg' for JPEG). It takes a URL, an image object or a product. Renditions are 200, 400, 800 and 1600 px and keep the picture's proportions, so crop: is accepted but does not cut: crop with CSS (object-fit: cover). An image that is not in the store's library comes back unchanged.
  • {{ url | image_tag: alt: '...', class: '...' }} writes an <img> with loading="lazy", the library's srcset and the named arguments as attributes.

Your own inputs

Add data-mobiari to any input to get the platform's mask and validity message:

<input name="cpf" data-mobiari="cpf" required>
<input name="telefone" type="tel" data-mobiari="phone">

Types: phone, cpf, cnpj, document (CPF or CNPJ), cep, email. A native required form then refuses a CPF with a wrong check digit like it refuses an empty field. The canonical value is in data-mobiari-value.

The store's own product fields

A store can define fields for its products and variants (wood type, warranty, width in cm) and choose which ones the storefront shows. Those arrive as product.fields, a list in the admin's order that only has fields with a value. Every item brings its own label, so a loop needs no knowledge of the store:

{% for field in product.fields %}
  <dt>{{ field.label }}</dt><dd>{{ field.display }}</dd>
{% endfor %}

field.value is the raw value (text, number, true/false, or a list for a multiple choice) and field.display the text for the page (120,5 cm, Sim, 24/10/2026, Carvalho, Pinus). field.group lets you build one table per group. To read one field by key, use product.field.<key>, for example {{ product.field.largura.display }}. Variants have the same variant.fields and variant.field.<key>. The default main-product section's specifications block already lists them after the specification groups. The full list of keys is in the theme reference.

Addresses of the built-in pages

A store can move the built-in pages: /produtos/{handle} can be /loja/{handle}, /carrinho can be /sacola, or the whole set can be English. Themes never hard-code those paths:

  • Link with the routes object: routes.cart_url, routes.account_url, routes.search_url, routes.wishlist_url, routes.products_url, routes.collections_url, and for one product or category routes.product_url_pattern / routes.collection_url_pattern (/loja/{handle}): {{ routes.product_url_pattern | replace: '{handle}', product.handle }}.
  • Links saved in menus and sections (/produtos, /products/x) are printed at the address in force.
  • Every earlier address (the platform's own, an English spelling, a previous choice) redirects permanently to the new one, so indexed pages and old links keep working. A theme from before addresses could move that prints {{ routes.products_url }}/{{ product.handle }} still lands on the product.

The addresses are a store setting, changed in the Mobiari admin under Storefront → Storefront addresses. Reading and changing them is not part of the public API yet. An address is lowercase words, - and _, ends with the page's placeholder when the page is one of many ({handle}, {number}, {id}), cannot start with a word the platform uses (/v1, /images, /files...), cannot answer the same address as another page, and cannot hide a page made in the editor. A store that changes nothing is served exactly as before.

The customer portal

/conta, /conta/pedidos, /conta/pedidos/{number}, /conta/produtos and /conta/entrar are rendered by the platform inside your layout/theme.liquid, so the header, footer and CSS stay yours. Customers sign in with a one-time code by e-mail (or WhatsApp) or a password, and see each item's stage (received, in production, shipped, delivered), shipments with tracking, the DANFE and any cartas de correção.

The session is an HttpOnly cookie on the store's own domain. Theme scripts cannot read it, and nothing should keep customer tokens in localStorage. Style the portal through the mobiari-portal classes (mp-card, mp-chip, mp-nav...).

Calling the API from a theme

Besides the Liquid forms (the mobiari-form snippet, the account portal, the platform's cart and search sections), a theme can talk to the Storefront API straight from its scripts, like a headless app. Two values are rendered into every page for that:

LiquidWhat it is
routes.api_urlThe API base on the store's own domain, /v1/storefront. Build calls from it: {{ routes.api_url }}/products?search=cama.
shop.storefront_keyThe store's publishable key (pk_live_...), or nil if the lookup failed.

On the store's own domain the request's Host already names the store, so a theme script needs no key; shop.storefront_key is for the rare script that calls the API from another origin. The key is public, but still treat it as configuration, not as a place to keep anything else.

The cart is the one thing a script has no id for. Use the alias current: the cart named by the cart_id cookie, started on the first write.

<script>
  const api = {{ routes.api_url | json }};
  async function add(variantId) {
    const res = await fetch(`${api}/carts/current/items`, {
      method: 'POST',
      credentials: 'same-origin',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ variant_id: variantId, quantity: 1 }),
    });
    const cart = await res.json(); // the whole cart, priced
    if (!res.ok) return alert(cart.error); // cart.code is `insufficient_stock`, ...
  }
</script>

When to use which:

  • Liquid and the platform's pieces for what the server can render: pages, the cart page, forms, the portal. They work without JavaScript.
  • The JSON API for what changes without a page load: the cart drawer, search suggestions, shipping estimates, wishlist.
  • The old /storefront-api/{store_slug}/api/... URLs are gone. Theme form endpoints (/storefront-api/{slug}/cart/add and friends) stay internal and answer the platform's own sections; do not build on them.

The SDK

Stores serve the browser build at /_/sdk/storefront.js. The platform adds it to any page that uses a <mobiari-...> element or a data-mobiari input, and it exposes window.Mobiari. A page whose only use is <mobiari-form> gets it when the first form is about to scroll into view (or takes the focus), so window.Mobiari does not exist before that; pages with data-mobiari inputs, <mobiari-login>, code in the page that calls Mobiari.createClient or Mobiari.br, and any page that loads a script file of its own (the platform cannot see what that file calls) load it at once.

The tracker script (/_/m.js) adds to the same object, whichever of the two loads first: Mobiari.track(name, props), Mobiari.identify(traits) and Mobiari.setCart(id). Guard the call, since the tracker can be blocked: if (window.Mobiari && Mobiari.track) Mobiari.track('view_product', {...}). The default theme's cart drawer adds Mobiari.cart to it as well: open(), close(), refresh(), add(variantId, qty, opts) and change(variantId, qty).

ElementWhat it does
<mobiari-form>A store form (above). Also <mobiari-form store="loja" form="contato"> to render one by itself.
<mobiari-login>Customer sign-in: code, password, forgot password.

Headless stores

Headless stores install @mobiari/storefront. One client covers the whole storefront API, typed from its OpenAPI document; Mobiari runs stock, freight, payment and orders, the store brings the pages. The client is built from the store's publishable key:

import { createClient, br } from '@mobiari/storefront'

const client = createClient({
  key: 'pk_live_...',
  apiBase: 'https://api.mobiari.com/v1',
})
GroupWhat it does
catalogProducts (filters, sort, cursor), categories, collections, shipping estimates, reviews, back-in-stock and price alerts.
wishlistSave products, with e-mail alerts for signed-in customers.
cartLines, discount code, contact, shipping or pickup, gift cards (selling them), credit (paying with codes and store credit).
checkoutPayment methods, installments, pay, wait for the payment.
customerSign-in, account, addresses, orders (with danfe and correction PDFs), returns, credit, privacy.
forms and locationsStore forms and the pickup points.

The method names, options and types are in the SDK's README (sdk/storefront/README.md); this page does not repeat them. To call the API without the SDK, or to see the sequence of calls from catalog to paid order, read the Storefront API guide.

Things worth knowing whichever way you call it:

  • Cards. Tokenize the card in the browser with the gateway's own SDK (the public key is in the payment-methods answer) and send the token. On a store whose card gateway is Asaas the payment's next_action.type is redirect: send the shopper to that page, then poll the payment. Card data never touches your server.
  • next_action is told apart by its type: pix_qr (qr_code_base64, copy_paste, expires_at), redirect (url) or card_result.
  • Errors carry a code (insufficient_stock, payment_required...); the guide lists them all. A failed payment is not an error: read the payment's status.
  • Validators. br.phone('(11) 98765-4321') and the other br validators run the same cases as the server (common::br), so the browser and the server never disagree about a CPF or a phone.
  • Returns. A signed-in customer can send items back. The returnable call says per order line how many units are left to return and whether they can ask now (open, otherwise closed_reason); the store approves or rejects the request (see returns).

Rules worth keeping

  • The server is the authority: validate in the browser for the visitor's sake, never instead of the server.
  • Never put customer tokens or personal data in localStorage or URLs.
  • Write forms and sign-in through the platform's pieces; a theme that posts its own copy loses the validation, spam protection and customer records.

On this page