Read product group data in Liquid

Enable public metafields, read linked product data in your Shopify theme, and troubleshoot empty or missing group data.

Use product.metafields.pl_swatches.groups.value to read the related products in a Color Swatches product group from your Shopify theme. Enable public metafields in Color Swatches first.

This guide is for separate Shopify products linked through Product groups. The data is a JSON metafield owned by each product: namespace pl_swatches, key groups.

Enable public group data

  1. Open Settings > Product groups in Color Swatches.

  2. In General, select Enable public metafields.

  3. Select Save.

  4. Allow the group data to sync before checking a product that belongs to a group.

The app creates and maintains the public copy for you. You do not need to create the metafield manually in Shopify or use a Color Swatches API token to read it in theme Liquid.

The public definition is named Platmart Swatches: Groups (public) in Shopify's product metafield definitions. The app's own app-scoped data is separate. If you disable Enable public metafields, the public copies are removed and custom Liquid that relies on them will stop receiving group data.

Read the groups in Liquid

Use this example in a product template where product is the current Shopify product. In a collection card snippet, replace product with the product variable used by that snippet.

{%- assign groups = product.metafields.pl_swatches.groups.value -%}
{%- assign product_base = routes.root_url | append: '/products/' | replace: '//', '/' -%}

{%- if groups != blank -%}
  {%- for group in groups -%}
    <h3>{{ group.option_name | escape }}</h3>
    <ul>
      {%- for swatch in group.swatches -%}
        <li>
          {%- if swatch.handle == product.handle -%}
            <span aria-current="page">{{ swatch.name | escape }}</span>
          {%- else -%}
            {%- assign sibling_url = product_base | append: swatch.handle -%}
            <a href="{{ sibling_url | escape }}">{{ swatch.name | escape }}</a>
          {%- endif -%}
        </li>
      {%- endfor -%}
    </ul>
  {%- endfor -%}
{%- endif -%}

The example renders text links to sibling products and marks the current product. Escape labels and URLs when outputting them into HTML. It does not reproduce the built-in widget's color/image styling or all its display rules.

Understand the returned data

.value gives you the parsed JSON array. Loop through its entries, then through each entry's swatches. Do not treat the metafield as a single product object.

  • group_id: identifies the product group.

  • option_name: the section label, such as Color or Fit.

  • swatches: entries containing handle, name, type, color_one, color_two, image, and out_of_stock. Color and image fields can be empty when they do not apply.

  • display_for: the section's display setting. linked: whether it is a linked group section.

A multi-option group can produce several entries with the same group_id, one per option section. Keep the entries separate if you want all the sections; do not deduplicate them by group_id. The payload reflects the app's group visibility rules, so it is not an unfiltered export of every group membership.

If the value is blank or a sibling is missing

  • Confirm Enable public metafields is saved and the group has finished syncing.

  • Check that the product belongs to a group and that your Liquid uses the correct product object.

  • Use the exact namespace and key: pl_swatches.groups, with .value to access the JSON data.

  • Check the group's display settings and visibility rules, including Hide inactive products. A filtered-out product may be absent from the swatch data.

If the value stays blank after these checks, send support the product URL, the group name, and the Liquid expression you tried. Do not manually overwrite this app-managed metafield to repair group data.

For variants within one Shopify product

Variant swatches use a different, shop-level dictionary: shop.metafields.pl_swatches.options.value. The public product-group toggle does not control that dictionary. It contains swatch configuration, not a list of sibling products or variant IDs, prices, and inventory. Reading it alone does not implement a working variant picker.

For more detail, see Public metafields and Reading swatch data in Liquid.

Did this answer your question?
๐Ÿ˜ž
๐Ÿ˜
๐Ÿ˜