Products

A shop window: products with photo, name, price, a button to buy on a payment page and one to order on WhatsApp.

When to use it

A small shop window: products with a photo, name and price, a button to pay on a payment page (Stripe, Mercado Pago, PayPal) and one to order on WhatsApp. It can read a collection.

When not to

Large stores with stock and checkout, which need a shop platform. Menus are better as dishes.

Accessibility

Each product is a list item with its name as a heading; buttons name the product they buy, so the links differ for screen readers.

See it live

The component library shows this component in the default theme, in every variant: open it in the component library

The products example as the component library shows it in the default theme

Where it is used

The starter sites that use it, each at a page that shows it:

Fields

What the component’s dialog asks for. In a Doc, keyed rows start with the key; rows in order follow the order below. One row, its cells in the order of the fields.

Field

Key

Kind

Required

Image

image

An image from the assets, with its description

No

Name

name

Plain text, one line

Yes

Price

price

Plain text, one line

No

Text

text

Plain text, one line

No

Link

link

A link: its text and address

No

Collection (a Sheet or JSON file in the data folder)

source

A value from a short list, or a setting

No

Keep only the items whose field or column has a value, as category = Mains or start >= today

filter

A value from a short list, or a setting

No

How many

limit

A value from a short list, or a setting

No

WhatsApp number

whatsapp

Plain text, one line

No

Variants

This component has no variants of its own; a theme can add some.

From a collection

Instead of writing its items one by one, the block can show the items of a collection: a Sheet tab or a JSON file in the content/data folder. Add these rows to the table, a name in the first cell and its value in the second:

  • source: the name of the collection, such as menu (required)
  • sort: the column to order the items by; a minus before it, such as -date, orders them backwards
  • limit: the most items to show
  • filter: keep only the items whose column has a value, such as category = Mains
  • whatsapp: a WhatsApp number: each product gets a link that opens a chat to order it

The first row of the collection names its columns. A name that matches no collection raises the warning unknown_data_source.

Warnings it can raise

The editor and the build say these when a block of this component needs a fix. All warnings are listed in the warnings reference.

Code

What it says

unknown_data_source

No collection named "{source}" in the data folder.

In Google Docs

A component is a table. Its first cell names it; the rows below hold its fields. This is the example table: The first row of the table here only names the columns; the Doc table is the rows below it.

Image

Name

Price

Text

Link

products

[Image]

Stoneware mug

€ 24

Hand-thrown, glazed in sand white.

Buy (https://example.com/pay/mug)

In a page file

In a site kept as a folder or in Git, the same component is a block of the page’s JSON file:

JSON
{
  "name": "products",
  "rows": [
    [
      {
        "image": "A stoneware mug"
      },
      "Stoneware mug",
      "€ 24",
      "Hand-thrown, glazed in sand white.",
      {
        "link": "Buy",
        "href": "https://example.com/pay/mug"
      }
    ]
  ]
}

Markup and classes

What the component writes takes these classes, for a theme’s CSS: the component’s own name, name__part for its parts and name--variant for each variant (the variant’s plain name is there too).

Class

What it marks

products

The component

products__actions

A part of it

products__body

A part of it

products__buy

A part of it

products__chat

A part of it

products__description

A part of it

products__image

A part of it

products__item

A part of it

products__media

A part of it

products__name

A part of it

products__price

A part of it

The HTML the example above writes, as the component library builds it in the default theme:

html
<ul class="products">
  <li class="products__item">
    <div class="products__media"><img class="products__image" src="/assets/img/5521e01d770e-1600.webp" srcset="/assets/img/5521e01d770e-400.webp 400w, /assets/img/5521e01d770e-800.webp 800w, /assets/img/5521e01d770e-1600.webp 1600w" sizes="(max-width: 800px) 100vw, 800px" alt="A stoneware mug" width="1800" height="900" fetchpriority="high" decoding="async"></div>
    <div class="products__body">
      <h3 class="products__name">Stoneware mug</h3>
      <p class="products__price">€ 24</p>
      <p class="products__description">Hand-thrown, glazed in sand white.</p>
      <div class="products__actions"><a class="button products__buy" href="https://example.com/pay/mug">Buy</a></div>
    </div>
  </li>
</ul>

Visitor texts

Texts it shows visitors, in the page’s language. Every one is in the visitor texts reference.

Key

Text

site.products.buy

Buy

site.products.whatsapp

Order on WhatsApp

site.products.message

Hello! I would like to order: {name}

Extending it

Its files in SeedPage. A theme or a site changes the markup by giving a file of the same name (the Liquid part), and a new component can extend this one.

  • src/components/products.js
  • src/components/products/products.liquid