LiquidProduct Pages

Product Pages

A product page has to let the shopper pick a variant, see that variant's price and stock, choose a quantity and add exactly that to the cart, all without a script. The pattern: a CSS-only radio picker shows one of several pre-rendered buttons, and each button carries its own variant.

A complete buy box

Pick a variant in the preview: the price, the stock line and the button change with it. Click Add to cart to see which variant would be added. Switch the route to Homepage and the section renders nothing, because it is guarded.

Buy box
Playground
Loading editor…

Runs in your browser on sample data: the same engine and filters as the storefront. Widgets such as add to cart are simulated: clicking one shows what would happen on a store.

How it works

  • One hidden radio per variant, before the buy box. A :checked ~ rule per variant shows the elements tagged -for-v1, -for-v2 and so on.
  • Loop product.variants even for a single-variant product: there is always one, and its id is what the checkout needs. Hide the picker with has_variants, not by skipping the loop.
  • Each button carries its own data-joomni-variant-id and data-joomni-has-variants="false", so the click adds that exact variant instead of opening the quick-add picker.
  • The quantity is a plain <select>. The button reads it by id when clicked (data-joomni-quantity-from). Cap it in the markup; the cart caps at 99 anyway.

Show stock only when it sells

“2,340 in stock” sells nothing; “Only 3 left” does. Show a count only behind tracks_inventory and a threshold.

Options and custom fields

product.options gives the axes (Size, Colour) and their values, for when you want to render a matrix instead of a flat list of variant titles. product.custom_fields holds anything extra the merchant added, like material or care.

Options and fieldsliquid
{%- if product.options.size > 0 -%}
{%- for option in product.options -%}
<fieldset style="border: 0; padding: 0 24px; margin: 16px 0; font-family: var(--font-body);">
<legend style="font-weight: 600;">{{ option.name }}</legend>
{%- for value in option.values -%}
<span style="display: inline-block; margin: 4px; padding: 6px 10px; border: 1px solid var(--color-border); border-radius: 6px;">{{ value }}</span>
{%- endfor -%}
</fieldset>
{%- endfor -%}
{%- endif -%}
{%- for field in product.custom_fields -%}
<p style="padding: 0 24px;"><strong>{{ field.label }}:</strong> {{ field.value }}</p>
{%- endfor -%}

Only for some products

A size guide belongs on clothes, not on mugs. Merchants can show a section for some products only with visibility rules, and inside the template you can branch on tags or type. See Conditional sections.

Still stuck? Our team reads every message.

Need help?