2.0 Beta

Smootify 2.0 is in public beta. Your 1.x store keeps working. Move when you want.

What changed

Metafields on the page

Show the Shopify metafields of a product and its variants. Covers what each type shows, lists, values written into attributes, colours, JSON, references, ratings, and elements shown or hidden by a metafield.

v2.0 beta
Open .md1.x page ↗
On this page
  1. Show a metafield
  2. What each type shows
  3. Lists
  4. Values in attributes, decimals and colours
  5. JSON
  6. References
  7. Ratings
  8. Show or hide by a metafield
  9. Coming from 1.x
  10. Before you publish

Metafields hold the extra data of a Shopify product or variant: a material, a care guide, a spec sheet, a list of ingredients. Smootify shows them on the page straight from Shopify, without copying them to the Webflow CMS. Build the product page shows the basic attribute. This page covers the rest: what each type shows, lists, values in attributes, JSON, references, ratings and conditions.

Note

In Shopify, each metafield needs a definition (Settings › Custom data) with Storefront access turned on. For a reference to a metaobject, the metaobject’s definition needs Storefront access too.

Show a metafield

metafield="material" on an element inside smootify-product shows the product metafield custom.material. Here is the whole path, from the Shopify admin to the page:

1 Settings › Custom data › Products › Add definition

MaterialProduct metafield definition
NameMaterial
Namespace and keycustom.material
TypeSingle line text
Storefronts access

Without Storefronts access, the value never reaches the page.

2 Products › Linen shirt › Metafields

Metafields
Materialcustom.materialLinen
Ratingreviews.rating4.5 out of 5

The rating is written by a review app, in its own namespace: reviews.

3 In Webflow, inside smootify-product

metafield="material"Material: Linen
metafield="rating" namespace="reviews"★★★★★★★★★★ 4.5

Smootify reads custom unless the element has namespace.

  • Namespace. Smootify reads the namespace custom unless you add namespace="…", for example namespace="reviews" for reviews.rating.
  • Variant metafields. variant-metafield="…" shows a metafield of the selected variant, and changes with it, a video included.
  • Where they work. metafield works inside smootify-product, on the product page and on product cards, and inside a cart line, where it reads the line’s product (Build the cart). variant-metafield works inside smootify-product and on variant cards (List the variants). Anywhere else, Smootify does not read the attribute.
  • Empty values. When the metafield is empty or missing, the element is hidden. What you type in the Designer stays as a placeholder until the value arrives. With data-fallback="…", the element stays and shows that text instead. An empty data-fallback is ignored, so a component can bind it to a text property that most instances leave empty.

What each type shows

Metafield typePut it onWhat it shows
Text, number, datea Text block or a Headingthe value; multi-line text keeps its line breaks
Rich texta Rich text elementthe text with its formatting
Moneya Text blockthe amount, formatted as a price
Weight, volume, dimensiona Text blockthe value with its unit, such as 650 g
True or falseany elementthe element, only when true
File: imagean Imagethe image
File: othera Text link or Link blocka link to the file
File: videoa Div blocka video that plays muted, on a loop
URL, linka Text link or Link blockthe link; a link type also sets the text
Color, ratingany elementa CSS variable: see below

Every type, list types included: metafield types.

Lists

A list of text, numbers, dates or measures is joined into one text, such as Cotton, Linen. Two ways to change that:

  • separator=" / " joins the values with the text you write, spaces included. The default is a comma and a space.
  • separator="repeat" makes one copy of the element per value. Design one item, and lay out the list as you like.
Example structure of the Navigator
Div Block
Text Block“Ingredient”metafield=ingredientsseparator=repeat

Lists of files, colours, URLs, links, ratings, references and metaobjects always make one copy of the element per item.

Values in attributes, decimals and colours

  • data-attr="aria-label" writes the value into that attribute instead of the element’s content. It works for text, whole numbers, ratings and values from JSON. Use it for a label that screen readers read, a title, or an image’s alt.
  • data-digits="1" rounds a decimal number, and the text of a rating, to that many decimals.
  • Colours. A colour metafield writes no text. It sets the CSS variable --metafield-color on the element, and property="--badge-color" gives the variable another name. Use the variable in your styles, for example as a background colour, so the merchant can change a badge colour in Shopify. A list of colours makes one copy of the element per colour, each with its own variable.

JSON

A JSON metafield shows nothing until data-path points at a value:

  • data-path="size.width" shows one value. Separate the keys with dots.
  • data-path="colors.0" shows the first item of a list. Positions count from 0.
  • A path that is not in the JSON hides the element.
Example structure of the Navigator
Div Block
Text Block“0”metafield=specsdata-path=size.width
Text Block“Colour”metafield=specsdata-path=colors.0

For several values of one metafield, you can also put data-path on elements inside a single metafield element, each with its own path. A path that leads to a list of objects repeats its element once per object, and the paths inside each copy start from that object. This makes a table of specs from JSON such as [{"label": "Height", "value": "90 cm"}].

Without any data-path, a JSON metafield is left to custom code: see Render a metafield yourself.

References

A metafield that references a product, a variant, a collection or a page shows it according to the element:

  • on a Text link or Link block, it links to it (a variant link opens the product page on that variant);
  • on an Image, it shows its image;
  • on an element without children, it shows its title.

Inside the element, reference="title", "url", "image", "handle", "description" (collections) and "body" (pages) show those parts. A part that the reference does not have is hidden. Pages have no URL on a Webflow site. A list of references repeats the element once per reference.

Example structure of the Navigator
Link Blockmetafield=pairs_with
Imagereference=image
Text Block“Product”reference=title

For product cards with a price and an add-to-cart button, use a smootify-product whose data-id names the metafield instead: see Product lists without the CMS.

Metaobjects. Inside an element with a metaobject reference, metaobject="field" shows a field of the metaobject. A list repeats the element once per metaobject. On a link inside it, metaobject-url="/materials/{handle}" builds the link from the metaobject’s handle. More in Show metaobjects.

Ratings

A rating metafield, such as reviews.rating from a review app:

  • on an element without children, shows the value as text, such as 4.5;
  • always sets the CSS variable --metafield-rating on the element: the rating as a share of its scale, such as 90% for 4.5 out of 5.

An element with children keeps them and only gets the variable. For stars, put a fill inside it that holds the row of stars, with its overflow hidden and a width of var(--metafield-rating): it covers that share of the row. data-attr="aria-label" gives the value to screen readers.

Example structure of the Navigator
Div Blockmetafield=ratingnamespace=reviewsdata-attr=aria-label
Text Block“★★★★★”

The review apps that write this metafield: Product reviews.

Show or hide by a metafield

if-metafield="key" shows an element only when the metafield says so, and unless-metafield="key" hides it. Both take namespace, and have a variant version: if-variant-metafield and unless-variant-metafield. For example, if-metafield="vegan" on a badge shows it only on products whose custom.vegan is true.

The metafield isif-metafield shows the element whenunless-metafield hides it when
true or falseit is trueit is true
a numberit is above 0it has a value
checked with data-check-value="Oak"it is Oak (a list: contains Oak)it is Oak (a list: contains Oak)
any other typeit has a valueit has a value

Every condition: product metafield conditions and variant metafield conditions.

Coming from 1.x

  • The types 1.x left to custom code now render: lists of numbers, dates, measures, colours, URLs and ratings, ratings, JSON with data-path, and references. A script listening to smootify.devMetafield still runs, after Smootify’s render: see Render a metafield yourself.
  • Weight and volume show the unit symbol, 650 g (1.x showed 650 GRAMS). Dates show the day saved in Shopify in every time zone.
  • separator keeps the spaces you write: separator=", " is a comma and a space (1.x trimmed it to a comma).

Before you publish

Check these first

  • A metafield stays empty. Its definition in Shopify needs Storefront access. For a metaobject reference, the metaobject’s definition needs it too.
  • Still empty with Storefront access. The namespace is not custom: add namespace="…".
  • The element keeps its placeholder text. It is outside smootify-product, a variant card or a cart line, where Smootify does not read metafields.
  • A list shows as one line. Add separator="repeat" to get one element per value.
  • A JSON metafield shows nothing. Add data-path with the key of the value.
  • The stars do not fill. The fill must be inside the element with the rating metafield, with a width of var(--metafield-rating).

    ↑ ↓ to moveEnter to openEsc to close