> ## Documentation Index
> Fetch the complete documentation index at: https://docs.loveful.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Web components

> The seven custom elements Loveful's storefront script defines, with their attributes, the markup they expect, the state they reflect and a working example of each.

Loveful's storefront script defines seven custom elements. Its theme blocks and the `loveful-wishlist` snippet render them for you, and you can write any of them into your own theme code: a section, a product card, a quick view, a custom header. For the bus they all talk to, see [JavaScript API](https://docs.loveful.app/developers/javascript-api.md).

| Element | What it is | Rendered for you by |
| - | - | - |
| [`<loveful-button>`](#loveful-button) | The save button, or a heart on a product card | Wishlist button block, `loveful-wishlist` snippet (`type: 'heart'`) |
| [`<loveful-count>`](#loveful-count) | The number of saved items | `loveful-wishlist` snippet (`type: 'count'`) |
| [`<loveful-header-icon>`](#loveful-header-icon) | A heart icon with a count badge | Nothing: write it yourself |
| [`<loveful-saved-count>`](#loveful-saved-count) | "Saved by N shoppers" on a product page | Saved count block |
| [`<loveful-list>`](#loveful-list) | The shopper's own wishlist | Wishlist block |
| [`<loveful-share-link>`](#loveful-share-link) | Copy link, reset link and email buttons | Wishlist block |
| [`<loveful-shared-list>`](#loveful-shared-list) | Someone else's shared wishlist | Shared wishlist block |

> [!WARNING]
>
> The **Loveful** app embed must be on (**Online Store > Themes > Customize > App embeds**). It loads `loveful.js` and `loveful.css`, and prints the page state the elements read: who is signed in, what they've saved, the merchant's design and translations. With the embed off, the elements are never upgraded and stay as the plain markup you wrote.

## How the elements work

* **They upgrade wherever they appear.** Each element sets itself up when it's added to the page, so markup added later (a quick view, a filtered collection grid, a section re-rendered by the theme editor) works with no extra code. Removing an element removes its listeners.
* **They share one state.** Every element follows `window.loveful`, so a save in one place updates every button, count and list on the page, and in the shopper's other tabs.
* **Strings come from Loveful's translations.** Labels such as "Save to wishlist" and "Saved by 3 shoppers" come from the app's locale file with the merchant's overrides from **Loveful > Translations** on top. The `data-*-text` and `data-*-label` attributes below are only fallbacks for a missing translation.
* **Theme Liquid can read Loveful's metafields.** The signed-in customer's saved variants (`refs_1`) and each product's and variant's saved count (`saved_count`) are readable in your theme under the app's namespace, `app--<id>`. Copy the namespace from your `loveful-wishlist` snippet (`customer.metafields['app--…']`); the examples below use `app--1234567`.

## loveful-button

The save button: a click saves the variant, a second click removes it. On a product page it follows the theme's variant picker; as a product card heart (`appearance="icon"`) it saves per product.

**Write it yourself** when the save button needs to sit somewhere the Wishlist button block can't go: inside a buy buttons group, a sticky add to cart bar, a quick view, or a product card. **Let Loveful render it** on a standard product template (the Wishlist button block) and on product cards (the `loveful-wishlist` snippet's heart).

### Attributes

| Attribute | Required | Default | Description |
| - | - | - | - |
| `variant-id` | Yes (or `data-vid`) | | The variant to save. Loveful rewrites it when the picker changes. |
| `data-vid` | | | The variant id for a card heart. Read when `variant-id` is missing. |
| `data-product-id` | Recommended | | The product id. Card hearts use it to tell whether any variant of the product is saved. |
| `data-pid` | | | The product id, as a card heart writes it. Read when `data-product-id` is missing. |
| `data-handle` | Recommended | | The product handle. Wishlist cards use it to link to the product and fetch its live price. A card heart needs it to fetch the product's details when saving. |
| `data-title` | Recommended | | The product title saved with the item. |
| `data-image` | | | An image URL saved with the item. |
| `data-price` | | | The price in major units (`45.0`, not `4500`). |
| `data-currency` | | | ISO currency code, such as `GBP`. |
| `data-available` | | `true` | `"false"` when the variant is sold out. |
| `appearance` | | | `"icon"` makes it a [card heart](#card-heart-mode). |
| `role`, `tabindex` | Yes | | Set `role="button"` and `tabindex="0"` yourself: Loveful handles Enter and Space, but doesn't add these. |
| `aria-pressed`, `data-saved` | | | Write them from Liquid for the right state on first paint (see the example). Loveful keeps them current from then on. |

`data-title`, `data-image`, `data-price`, `data-currency` and `data-available` are only used for a guest's list (kept on their device) and for the card drawn on the wishlist page straight after a save. A signed-in shopper's wishlist page is rendered from the live variant, so a missing detail there corrects itself.

### Markup inside it

None needed. The content is rebuilt on every state change from the merchant's choice in Loveful's storefront design window (**Button content**):

| Content | What Loveful renders inside |
| - | - |
| Text | The label, "Save to wishlist" or "Saved". |
| Icon | `<svg class="loveful-button__icon">`, with `aria-label` set to the label. |
| Icon and text | The icon and `<span class="loveful-button__label">`. |

Whatever you write inside is shown only until the script runs, so write the label (or nothing). A card heart's content is left alone: its heart is drawn in CSS.

### State and events

| On the element | When |
| - | - |
| `data-saved` | The variant (or, for a card heart, any variant of the product) is saved. |
| `aria-pressed` | `"true"` or `"false"`, in step with `data-saved`. |
| `data-pending` | A save or remove is in flight. Clicks are ignored meanwhile. |
| `variant-id` | Rewritten when the variant picker changes. |
| `hidden` | Removed when the element is set up. Render it with `hidden` to show it only once Loveful is running. |

It listens for the bus's `item_added` and `item_removed`, and on `document` for the [variant picker events](https://docs.loveful.app/developers/javascript-api.md#events-loveful-listens-for) (`shopify:product:select`, `variant:update`, `variant:change` and `change`). It dispatches nothing itself: listen for the bus's [`item_added` and `item_removed`](https://docs.loveful.app/developers/javascript-api#bus-events) instead.

When the shopper isn't signed in and the store requires an account to save, a click opens a sign-in dialog. When a signed-in shopper's list is full (128 items), a click asks whether to remove the oldest item to make room.

### Example

> [tab] Liquid
>
> ```liquid snippets/my-save-button.liquid theme={null}
> {%- liquid
>   assign variant = product.selected_or_first_available_variant
>   assign image = variant.image | default: product.featured_image
>   assign saved = false
>   if customer
>     assign saved_ids = customer.metafields['app--1234567'].refs_1.value | map: 'id' | join: ','
>     assign saved_ids = ',' | append: saved_ids | append: ','
>     assign needle = ',' | append: variant.id | append: ','
>     if saved_ids contains needle
>       assign saved = true
>     endif
>   endif
> -%}
> <loveful-button
>   variant-id="{{ variant.id }}"
>   data-product-id="{{ product.id }}"
>   data-handle="{{ product.handle }}"
>   data-title="{{ product.title | escape }}"
>   data-image="{% if image %}{{ image | image_url: width: 400 }}{% endif %}"
>   data-price="{{ variant.price | divided_by: 100.0 }}"
>   data-currency="{{ cart.currency.iso_code }}"
>   data-available="{{ variant.available }}"
>   role="button"
>   tabindex="0"
>   aria-pressed="{{ saved }}"
>   {% if saved %}data-saved{% endif %}
> >{% if saved %}Saved{% else %}Save to wishlist{% endif %}</loveful-button>
> ```

> [tab] HTML
>
> ```html theme={null}
> <loveful-button
>   variant-id="44012345678901"
>   data-product-id="8012345678901"
>   data-handle="linen-shirt"
>   data-title="Linen shirt"
>   data-image="https://cdn.shopify.com/s/files/1/0000/0001/products/linen-shirt.jpg"
>   data-price="45.0"
>   data-currency="GBP"
>   data-available="true"
>   role="button"
>   tabindex="0"
>   aria-pressed="false"
> >Save to wishlist</loveful-button>
> ```

The saved check is optional: without it the button shows as unsaved until the script runs, then corrects itself.

### Card heart mode

With `appearance="icon"`, the button is a heart for a product card:

* It's saved when **any** variant of the product is saved, and a click on a saved heart removes every saved variant of the product.
* It ignores the variant picker.
* Its click doesn't follow a link it sits in (the default and propagation are stopped), so it can go inside a card that is one big link.
* It needs only `data-vid`, `data-pid` and `data-handle`: when saving, it fetches the title, image, price and stock from `/products/<handle>.js`.
* It's positioned absolutely over the top right of its container, so the container needs `position: relative`. The app embed's **Product card heart** settings move it (top left, or in line) and colour it.
* Loveful sets its `aria-label` to "Save to wishlist" or "Saved".

```liquid theme={null}
<div class="card__media" style="position: relative">
  {{ card_product.featured_media | image_url: width: 600 | image_tag }}
  <loveful-button
    appearance="icon"
    data-vid="{{ card_product.selected_or_first_available_variant.id }}"
    data-pid="{{ card_product.id }}"
    data-handle="{{ card_product.handle }}"
    role="button"
    tabindex="0"
    aria-pressed="false"
  ></loveful-button>
</div>
```

The [`loveful-wishlist` snippet](https://docs.loveful.app/developers/guides/card-hearts) renders exactly this, with the saved state worked out in Liquid, so use it unless you need different markup.

### Styling

Classes: `loveful-button__icon`, `loveful-button__label`. Style states with `loveful-button[data-saved]`, `loveful-button[data-pending]` and `loveful-button[appearance="icon"]`.

| Variable | Sets |
| - | - |
| `--loveful-btn-bg`, `--loveful-btn-fg`, `--loveful-btn-border` | Colours when not saved |
| `--loveful-btn-saved-bg`, `--loveful-btn-saved-fg`, `--loveful-btn-saved-border` | Colours when saved and on hover |
| `--loveful-btn-padding`, `--loveful-btn-radius`, `--loveful-btn-width` | Shape |
| `--loveful-btn-icon-size`, `--loveful-btn-gap` | The icon |
| `--loveful-card-size`, `--loveful-card-color`, `--loveful-card-saved-color`, `--loveful-card-bg`, `--loveful-card-heart-offset` | The card heart |

All of them: [Save button](https://docs.loveful.app/developers/css-variables.md#save-button) and [Product card heart](https://docs.loveful.app/developers/css-variables.md#product-card-heart-snippet).

## loveful-count

The number of items on the shopper's default list, kept current as they save and remove anywhere on the site.

**Write it yourself** for a count beside your own header icon, in a mobile menu, or in a heading on the wishlist page. **Let Loveful render it** in the header with the [`loveful-wishlist` snippet](https://docs.loveful.app/developers/guides/header-link) (`type: 'count'`), which wraps it in a link with a heart.

### Attributes

| Attribute | Required | Default | Description |
| - | - | - | - |
| `data-cap` | | `99` | Above this the count shows as `99+`. |
| `data-hide-at-zero` | | `true` | Set `"false"` to keep it visible at zero. |

### Markup inside it

None. Its text is replaced with the count. Write the count from Liquid for the right number on first paint.

### State and events

| On the element | When |
| - | - |
| `data-count` | Always: the uncapped count. |
| `hidden` | The count is zero, unless `data-hide-at-zero="false"`. |

It listens for the bus's `item_added` and `item_removed`. It dispatches nothing.

### Example

> [tab] Liquid
>
> ```liquid theme={null}
> {%- assign loveful_count = customer.metafields['app--1234567'].refs_1.value | size -%}
> <a href="/pages/wishlist" class="header__icon">
>   <span>Wishlist</span>
>   <loveful-count class="header__badge" data-cap="9" {% if loveful_count == 0 %}hidden{% endif %}>{{ loveful_count }}</loveful-count>
> </a>
> ```

> [tab] HTML
>
> ```html theme={null}
> <a href="/pages/wishlist">
>   Wishlist (<loveful-count data-hide-at-zero="false">0</loveful-count>)
> </a>
> ```

A guest's count comes from their device, so it's `0` in Liquid and fills in when the script runs.

### Styling

No classes of its own; it's `display: inline-block` with tabular numbers. Inside `.loveful-header-link` (the snippet's link) it's drawn as a badge, set with `--loveful-header-count-bg`, `--loveful-header-count-fg` and `--loveful-header-count-size`. See [Header link and icon](https://docs.loveful.app/developers/css-variables.md#header-link-and-icon).

## loveful-header-icon

A ready-made heart icon with a [`<loveful-count>`](#loveful-count) badge, for a header that has no wishlist icon of its own.

**Write it yourself**: no block or snippet renders it. The snippet's header link (`type: 'count'`) is the alternative, drawn with CSS instead.

### Attributes

| Attribute | Required | Default | Description |
| - | - | - | - |
| `aria-label` | | The `loveful.header_label` translation | Read aloud for the icon. Loveful sets it from your translations only when it's missing. |

### Markup inside it

Leave it empty. When it's empty, Loveful fills it with `<svg class="loveful-header-icon__svg">` and a `<loveful-count>` (hidden at zero). If it already has any child element, Loveful leaves it as it is, so it's empty until the script runs.

### State and events

None of its own. The `<loveful-count>` inside it follows saves and removes.

### Example

It isn't a link, so wrap it in one:

```liquid theme={null}
<a href="{{ pages.wishlist.url | default: '/pages/wishlist' }}" class="header__icon">
  <loveful-header-icon></loveful-header-icon>
</a>
```

### Styling

Classes: `loveful-header-icon__svg`, and `loveful-header-icon loveful-count` for the badge.

| Variable | Sets |
| - | - |
| `--loveful-icon-size`, `--loveful-icon-color` | The heart |
| `--loveful-count-bg`, `--loveful-count-fg` | The badge |

See [Header link and icon](https://docs.loveful.app/developers/css-variables.md#header-link-and-icon) and [Saved count](https://docs.loveful.app/developers/css-variables.md#saved-count).

## loveful-saved-count

"Saved by N shoppers" on a product page, for the whole product or the selected variant. It follows the variant picker and the shopper's own saves, so it moves by one when they save or remove.

**Write it yourself** to put the count somewhere the Saved count block can't go, or on a product card. **Let Loveful render it** with the Saved count block on a product template.

### Attributes

| Attribute | Required | Default | Description |
| - | - | - | - |
| `variant-id` | For `variant` scope | | The selected variant. Loveful rewrites it when the picker changes. |
| `data-scope` | | `product` | `product` counts the whole product; `variant` counts the selected variant. |
| `data-product-count` | For `product` scope | `0` | The product's saved count, from its `saved_count` metafield. |
| `data-min` | | `1` | Hidden below this count. |

### Markup inside it

| Child | Required | Description |
| - | - | - |
| `<script type="application/json" data-variant-counts>` | Yes | Every variant's saved count, as `{ "<variant id>": <count> }`. Read once, when the element is set up. |
| `.loveful-saved-count__text` | Recommended | Where the text goes. |
| `svg.loveful-saved-count__icon` | | An icon beside the text. |

Without the `data-variant-counts` script, the `variant` scope always counts from `0`, and the `product` scope can't tell which variants the shopper's own saves belong to, so it stops following them. Without `.loveful-saved-count__text`, Loveful swaps the element's own text and leaves its other children, such as an icon, in place.

Loveful draws the text as soon as the element is on the page, with the `loveful.saved_count_one` or `loveful.saved_count_other` translation, and again on every change. Render the text and `hidden` from Liquid too, so the count shows before the script runs.

### State and events

| On the element | When |
| - | - |
| `hidden` | The count is below `data-min`. |
| `variant-id` | Rewritten when the variant picker changes. |

It listens for the bus's `item_added` and `item_removed`, and for the [variant picker events](https://docs.loveful.app/developers/javascript-api.md#events-loveful-listens-for). It dispatches nothing.

### Example

```liquid snippets/my-saved-count.liquid theme={null}
{%- liquid
  assign loveful_ns = 'app--1234567'
  assign variant = product.selected_or_first_available_variant
  assign count = product.metafields[loveful_ns].saved_count.value | default: 0
-%}
<loveful-saved-count
  variant-id="{{ variant.id }}"
  data-scope="product"
  data-min="1"
  data-product-count="{{ count }}"
  {% if count < 1 %}hidden{% endif %}
>
  <span class="loveful-saved-count__text">Saved by {{ count }} {% if count == 1 %}shopper{% else %}shoppers{% endif %}</span>
  <script type="application/json" data-variant-counts>
    { {%- for v in product.variants -%}
      "{{ v.id }}": {{ v.metafields[loveful_ns].saved_count.value | default: 0 }}
      {%- unless forloop.last %},{% endunless -%}
    {%- endfor -%} }
  </script>
</loveful-saved-count>
```

For the selected variant's count, set `data-scope="variant"` and start from `variant.metafields[loveful_ns].saved_count.value`.

### Styling

Classes: `loveful-saved-count__text`, `loveful-saved-count__icon`.

| Variable | Sets |
| - | - |
| `--loveful-count-color`, `--loveful-count-size` | The text |
| `--loveful-count-gap`, `--loveful-count-icon-size` | The icon |

See [Saved count](https://docs.loveful.app/developers/css-variables.md#saved-count).

## loveful-list

The shopper's own wishlist. It keeps the cards in step with saves and removes, draws a guest's cards from their device, refreshes those with live prices and stock, and handles each card's remove, Change and add to cart controls.

**Write it yourself** to build a wishlist page with your own card markup or layout. **Let Loveful render it** with the Wishlist block: its cards follow the merchant's storefront design and come with ratings, stock and the change options dialog set up.

### Attributes

| Attribute | Required | Default | Description |
| - | - | - | - |
| `data-guest` | For guests | | The shopper isn't signed in. Cards are drawn from their device, or a sign-in prompt shows when the store requires an account. Set it from Liquid: `{% unless customer %}data-guest{% endunless %}`. |
| `data-preview` | | | The element does nothing. For theme editor sample cards. |

### Markup inside it

| Child | Required | Description |
| - | - | - |
| `ul.loveful-list` | Yes | Where cards go. Without it, no card is ever added. |
| `li.loveful-card[data-variant-id][data-handle]` | For signed-in shoppers | One per saved variant, rendered by your Liquid. Loveful doesn't fetch a signed-in shopper's list: it only removes cards and adds new ones. |
| `template[data-loveful-card]` | Yes | One `li.loveful-card`, cloned for a guest's cards and for saves made after the page loaded. Without it, those never appear. |
| `.loveful-list__empty` | Recommended | Shown when there are no cards, hidden otherwise. For a guest on a store that requires an account, it's replaced with a sign-in prompt (`.loveful-list__sign-in`). |

Inside a cloned card, Loveful fills whichever of these it finds:

| Element in the card | Filled with |
| - | - |
| `a.loveful-card__media`, `a.loveful-card__title` | `href` to the product, with `?variant=` |
| `.loveful-card__img` | `src` and `alt`, or `hidden` with no image. `.loveful-card__placeholder` is removed once there's an image. |
| `.loveful-card__title` | The product title |
| `.loveful-card__variant` | The variant title, such as `Red / M` |
| `.loveful-card__price` | The price, with `<s class="loveful-card__compare">` when it's on sale |
| `.loveful-card__stock` | "Sold out", or empty |
| `.loveful-card__rating` | Star rating, when the product has reviews (shown by removing `hidden`) |
| `.loveful-card__change` | Hidden when the product has a single variant |
| `form.loveful-card__cart input[name="id"]` | The variant id |
| `.loveful-card__add` | "Add to cart", or disabled and "Sold out" |
| `.loveful-card__remove` | `data-loveful-remove` and an `aria-label` |

Controls, on any card in the list:

| Control | On click |
| - | - |
| `[data-loveful-remove="<variant id>"]` | Removes the item. Its card goes when the remove succeeds. |
| `[data-loveful-change]` | Opens the change options dialog for its `li.loveful-card`, which needs `data-variant-id` and `data-handle`. |
| `form.loveful-card__cart` | Submitting adds the variant to the cart through Shopify's storefront actions and opens the cart drawer, or posts the form to `/cart/add` where they're missing. |

### State and events

| On the element or its cards | When |
| - | - |
| `.loveful-list__empty[hidden]` | There's at least one card. |
| `li.loveful-card[data-swap-to]` | The card's options are being changed, with the new variant id. |

It listens for the bus's `item_added` (adds a card, newest first) and `item_removed` (removes its card). On setup it publishes the `loveful:wishlist_page_viewed` [Shopify customer event](https://docs.loveful.app/developers/javascript-api.md#shopify-customer-events).

### Example

The signed-in shopper's cards come from the customer's `refs_1` metafield, the same list the Wishlist block renders. A guest gets an empty list that Loveful fills from their device.

```liquid sections/my-wishlist.liquid theme={null}
{%- assign loveful_refs = customer.metafields['app--1234567'].refs_1.value -%}
<loveful-list {% unless customer %}data-guest{% endunless %}>
  <ul class="loveful-list" role="list">
    {%- if loveful_refs != blank -%}
      {%- paginate loveful_refs by 128 -%}
        {%- for variant in loveful_refs -%}
          {%- assign image = variant.image | default: variant.product.featured_image -%}
          <li class="loveful-card" data-variant-id="{{ variant.id }}" data-handle="{{ variant.product.handle }}">
            <a class="loveful-card__media" href="{{ variant.url }}" tabindex="-1" aria-hidden="true">
              {%- if image -%}{{ image | image_url: width: 600 | image_tag: class: 'loveful-card__img', alt: '', loading: 'lazy' }}{%- endif -%}
            </a>
            <a class="loveful-card__title" href="{{ variant.url }}">{{ variant.product.title }}</a>
            <span class="loveful-card__variant">{% unless variant.product.has_only_default_variant %}{{ variant.title }}{% endunless %}</span>
            <span class="loveful-card__price">{{ variant.price | money }}</span>
            <form class="loveful-card__cart" method="post" action="{{ routes.cart_add_url }}">
              <input type="hidden" name="id" value="{{ variant.id }}">
              <input type="hidden" name="quantity" value="1">
              <button class="loveful-card__add" type="submit" {% unless variant.available %}disabled{% endunless %}>
                {%- if variant.available %}Add to cart{% else %}Sold out{% endif -%}
              </button>
            </form>
            <button class="loveful-card__remove" type="button" data-loveful-remove="{{ variant.id }}">Remove</button>
          </li>
        {%- endfor -%}
      {%- endpaginate -%}
    {%- endif -%}
  </ul>

  <div class="loveful-list__empty" {% if loveful_refs != blank %}hidden{% endif %}>
    <p>Your wishlist is empty.</p>
  </div>

  <template data-loveful-card>
    <li class="loveful-card">
      <a class="loveful-card__media" href="#" tabindex="-1" aria-hidden="true">
        <img class="loveful-card__img" alt="" loading="lazy" width="600" height="600">
      </a>
      <a class="loveful-card__title" href="#"></a>
      <span class="loveful-card__variant"></span>
      <span class="loveful-card__price"></span>
      <form class="loveful-card__cart" method="post" action="{{ routes.cart_add_url }}">
        <input type="hidden" name="id">
        <input type="hidden" name="quantity" value="1">
        <button class="loveful-card__add" type="submit">Add to cart</button>
      </form>
      <button class="loveful-card__remove" type="button">Remove</button>
    </li>
  </template>
</loveful-list>
```

Add a `<button class="loveful-card__change" type="button" data-loveful-change>Change</button>` to the cards to offer the change options dialog.

### Styling

Classes: `loveful-list` (the grid), `loveful-card`, `loveful-card--top` and `loveful-card--side` (image layouts), every `loveful-card__*` element above, `loveful-card__remove--overlay` and `loveful-card__remove--link`, `loveful-list__empty`, `loveful-list__browse`, `loveful-list__sign-in`.

| Variable | Sets |
| - | - |
| `--loveful-columns`, `--loveful-columns-tablet`, `--loveful-columns-mobile`, `--loveful-gap` | The grid: desktop above 990px, tablet from 750px |
| `--loveful-card-gap`, `--loveful-card-align`, `--loveful-card-ratio`, `--loveful-card-image-radius` | The card |
| `--loveful-card-title-size`, `--loveful-card-title-weight`, `--loveful-card-price-size` | Card text |

See [Wishlist page](https://docs.loveful.app/developers/css-variables.md#wishlist-page), [Wishlist cards](https://docs.loveful.app/developers/css-variables.md#wishlist-cards), [Add to cart](https://docs.loveful.app/developers/css-variables.md#add-to-cart) and [Remove button](https://docs.loveful.app/developers/css-variables.md#remove-button).

## loveful-share-link

The share controls for a signed-in shopper's own wishlist: **Copy link**, **Reset link** and, when email sharing is on, **Email wishlist**. Copy and reset put the link on the clipboard; email opens a form in a dialog.

**Write it yourself** to put the share controls somewhere other than above the list, or with your own buttons. **Let Loveful render it** with the Wishlist block, which adds it only once a share page is set up in Loveful's Share settings and matches email sharing to those settings.

### Attributes

| Attribute | Required | Default | Description |
| - | - | - | - |
| `data-path` | Recommended | | The share page's path, such as `/pages/shared-wishlist`. With it, Copy link copies straight away from the token the page already has; without it, the first copy asks Loveful for the link. |
| `data-email` | | | Adds the **Email wishlist** button. Add it only when email sharing is on in Loveful's Share settings, or sending fails. |
| `data-message` | | | Adds an optional message field to the email form. |
| `data-name` | | | Prefills the sender's name in the email form. |
| `data-reset-confirm` | | The `loveful.share_reset_confirm` translation | The browser confirmation shown before a reset. |

Loveful's buttons and messages use your translations (`loveful.share_copy`, `loveful.share_reset`, `loveful.share_copied` and the rest), set on **Settings › Translations**.

### Markup inside it

Leave it empty for Loveful's own buttons: `button.loveful-share-link__copy`, `button.loveful-share-link__reset` and `button.loveful-share-link__email`.

Or write your own controls. When the element already has children, Loveful leaves them in place and handles clicks on any of these inside it:

| Control | On click |
| - | - |
| `[data-loveful-share-copy]` | Copies the share link. The label shows "Copied!" for two seconds. |
| `[data-loveful-share-reset]` | Asks to confirm, makes a new link (the old one stops working) and copies it. |
| `[data-loveful-share-email]` | Opens the email form. |

> [!NOTE]
>
> The "Copied!" and "Link reset" messages replace only the button's words, then the original words come back. Loveful swaps the content of a `[data-loveful-label]` element inside the button if there is one, or else the button's last piece of text, so an icon inside the button stays.

### State and events

| On the element | When |
| - | - |
| `hidden` | The shopper isn't signed in: guests can't share. Render it with `hidden` and Loveful shows it for signed-in shoppers. |
| `data-pending` | A copy or reset is waiting for Loveful. |

It dispatches these on itself, bubbling, so they can be caught on `document`:

| Event | `detail` |
| - | - |
| `loveful:share_link_copied` | `{ share_url }`, plus `token` when the link was just made |
| `loveful:share_link_reset` | `{ token, share_url }` |
| `loveful:share_emailed` | None |

### Example

> [tab] Loveful's buttons
>
> ```liquid theme={null}
> {%- if customer -%}
>   <loveful-share-link
>     hidden
>     data-path="/pages/shared-wishlist"
>     data-email
>     data-message
>     data-name="{{ customer.first_name | escape }}"
>   ></loveful-share-link>
> {%- endif -%}
> ```

> [tab] Your own controls
>
> ```liquid theme={null}
> {%- if customer -%}
>   <loveful-share-link hidden data-path="/pages/shared-wishlist" class="wishlist-share">
>     <button type="button" class="button" data-loveful-share-copy>
>       <svg class="icon" aria-hidden="true" viewBox="0 0 24 24"><path d="…"/></svg>
>       <span data-loveful-label>Share my wishlist</span>
>     </button>
>     <button type="button" class="link" data-loveful-share-reset>Get a new link</button>
>   </loveful-share-link>
> {%- endif -%}
>
> <script>
>   document.addEventListener("loveful:share_link_copied", (e) => {
>     console.log("Shared", e.detail.share_url);
>   });
> </script>
> ```

### Styling

Classes: `loveful-share-link__copy`, `loveful-share-link__reset`, `loveful-share-link__email`. The email form uses the dialog classes (`loveful-dialog`, `loveful-email-dialog`, `loveful-dialog__field`, `loveful-dialog__actions`).

| Variable | Sets |
| - | - |
| `--loveful-share-align`, `--loveful-share-gap` | The row |
| `--loveful-share-btn-bg`, `--loveful-share-btn-fg`, `--loveful-share-btn-border` | Button colours |
| `--loveful-share-btn-padding`, `--loveful-share-btn-border-width` | Button shape |
| `--loveful-muted-opacity` | The Reset button's fade |

See [Share buttons](https://docs.loveful.app/developers/css-variables.md#share-buttons), [Dialogs](https://docs.loveful.app/developers/css-variables.md#dialogs) and [Form fields](https://docs.loveful.app/developers/css-variables.md#form-fields).

## loveful-shared-list

A wishlist someone shared, loaded from the token in the share link (`?loveful_token=…`). It works for anyone: the viewer doesn't need to be signed in.

**Write it yourself** to show a shared list on a page of your own design, or as a plain list without cards. **Let Loveful render it** with the Shared wishlist block, on the page picked in Loveful's Share settings: share links open that page.

It has two modes, picked by its markup:

* **Block mode**: it contains a `ul.loveful-list`. The items are drawn as cards from your `template[data-loveful-card]`, exactly like [`<loveful-list>`](#loveful-list), and refreshed with live prices and stock.
* **Bare mode**: it doesn't. Loveful replaces its content with a plain list of links.

### Attributes

| Attribute | Required | Default | Description |
| - | - | - | - |
| `token` | | | The share token. When it's missing, the token comes from the page URL. |
| `data-param` | | `loveful_token` | The URL query parameter the token is read from. |
| `data-preview` | | | The element does nothing. For theme editor sample cards. |

### Markup inside it

**Block mode:**

| Child | Required | Description |
| - | - | - |
| `ul.loveful-list` | Yes | Where cards go. Its contents are replaced when the list loads. |
| `template[data-loveful-card]` | Yes | One `li.loveful-card`, cloned per item and filled as in [`<loveful-list>`](#loveful-list). Without it, no cards appear. |
| `.loveful-list__empty` | Recommended | Shown with its own text for an empty list, and with the `loveful.shared_not_available` translation for a missing or reset link. |

Leave the remove and Change controls out of the template: it's someone else's list. A card's `form.loveful-card__cart` adds to the viewer's cart, as on the wishlist page.

**Bare mode:** leave it empty, or put a loading message inside. Loveful replaces it with:

```html theme={null}
<ul class="loveful-shared-list">
  <li class="loveful-shared-list__item">
    <a class="loveful-shared-list__link" href="/products/linen-shirt?variant=44012345678901">
      <img class="loveful-shared-list__img" src="…" alt="Linen shirt" loading="lazy">
      <div class="loveful-shared-list__body">
        <span class="loveful-shared-list__title">Linen shirt</span>
        <span class="loveful-shared-list__price">£45.00</span>
      </div>
    </a>
  </li>
</ul>
```

or `<p class="loveful-shared-list__empty">` with the `loveful.shared_empty` translation for an empty list, or `<p class="loveful-shared-list__missing">` with the `loveful.shared_not_available` translation for a missing or reset link. Bare mode shows the price saved with the item, not the live price, formatted for the page's language.

### State and events

Nothing is reflected on the element. It loads once, after `loveful.ready`. When the list has items, it:

* sets the hidden cart attribute `_loveful_share` to the token (or `<token>:<send id>` when the link came from a share email's `s` parameter), so an order can be traced back to the share;
* publishes the `loveful:share_viewed` [Shopify customer event](https://docs.loveful.app/developers/javascript-api.md#shopify-customer-events).

### Example

> [tab] Block mode
>
> ```liquid templates/page.shared-wishlist.liquid theme={null}
> <h1>{{ page.title }}</h1>
> <loveful-shared-list {% if request.design_mode %}data-preview{% endif %}>
>   <ul class="loveful-list" role="list"></ul>
>   <p class="loveful-list__empty" hidden>This wishlist is empty.</p>
>   <template data-loveful-card>
>     <li class="loveful-card">
>       <a class="loveful-card__media" href="#" tabindex="-1" aria-hidden="true">
>         <img class="loveful-card__img" alt="" loading="lazy" width="600" height="600">
>       </a>
>       <a class="loveful-card__title" href="#"></a>
>       <span class="loveful-card__variant"></span>
>       <span class="loveful-card__price"></span>
>       <span class="loveful-card__stock"></span>
>       <form class="loveful-card__cart" method="post" action="{{ routes.cart_add_url }}">
>         <input type="hidden" name="id">
>         <input type="hidden" name="quantity" value="1">
>         <button class="loveful-card__add" type="submit">Add to cart</button>
>       </form>
>     </li>
>   </template>
> </loveful-shared-list>
> ```

> [tab] Bare mode
>
> ```html theme={null}
> <loveful-shared-list>
>   <p>Loading wishlist…</p>
> </loveful-shared-list>
> ```

> [tab] Fixed token
>
> ```html theme={null}
> <!-- A token from somewhere other than the URL, such as a gift guide -->
> <loveful-shared-list token="Xk2pQ9vLm4"></loveful-shared-list>
>
> <!-- Links that use ?list=<token> instead of ?loveful_token= -->
> <loveful-shared-list data-param="list"></loveful-shared-list>
> ```

> [!NOTE]
>
> Share links Loveful makes always point at the share page picked in Loveful's Share settings, with `?loveful_token=`. Put the element on that page, or set `data-param` only for links you build yourself.

### Styling

Block mode uses the [`<loveful-list>` classes and variables](#loveful-list). Bare mode's classes are `loveful-shared-list` (an auto-filling grid, 12rem minimum columns), `loveful-shared-list__item`, `__link`, `__img`, `__body`, `__title`, `__price`, `__empty` and `__missing`; it has no variables of its own, so style the classes directly. See [Shared](https://docs.loveful.app/developers/css-variables.md#shared).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.