> ## 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.

# Building with Loveful

> What a theme developer can build with Loveful: web components, the window.loveful bus, storefront events, CSS variables and webhooks, and how they fit together.

Loveful's blocks cover a standard theme without code. When a theme needs more, everything the blocks use is open to you: put a save button anywhere, build your own wishlist page, react to saves in your own scripts, restyle every element, and receive wishlist events on your own server.

> [card] [Web components](https://docs.loveful.app/developers/web-components.md)
>
> Seven custom elements: save button, counts, wishlist, share controls and shared list.

> [card] [JavaScript API](https://docs.loveful.app/developers/javascript-api.md)
>
> The `window.loveful` bus: saved state, events, clearing and sharing.

> [card] [CSS variables](https://docs.loveful.app/developers/css-variables.md)
>
> Every `--loveful-*` custom property, with its default.

> [card] [Webhooks](https://docs.loveful.app/developers/webhooks.md)
>
> Signed wishlist events posted to your own URLs.

## How the pieces fit

```text theme={null}
Loveful app embed (theme editor > App embeds)
  ├─ prints the page state: who's signed in, their saved items, design, translations
  ├─ loads loveful.css  → reads --loveful-* variables
  └─ loads loveful.js   → window.loveful (the bus)
                           ├─ defines the <loveful-*> elements
                           ├─ fires events on the bus, on document and to Shopify's customer events
                           └─ sends saves and removes to Loveful through the app proxy
                                 └─ Loveful posts webhooks to your endpoints
```

* **The app embed is required.** It's the only thing that loads Loveful on the storefront. Blocks, the snippet and your own markup all do nothing while it's off.
* **Nothing is fetched on page load.** A signed-in shopper's saved items come from their customer metafields, printed by the embed. A guest's are kept in their browser and move to their account when they sign in.
* **Every element follows one state.** A save anywhere updates every button, count and list on the page, and in the shopper's other tabs.
* **Liquid can read the same data.** The signed-in customer's saved variants (`refs_1`) and each product's and variant's saved count (`saved_count`) are readable under the app's metafield namespace, `app--<id>`. Copy it from your `loveful-wishlist` snippet (Settings > Storefront fills it in).

## Quick start

**1. Turn on the app embed**

In the theme editor, open **App embeds** and switch on **Loveful**. Check with `window.loveful` in the browser console on any storefront page.

**2. Create the loveful-wishlist snippet**

In Loveful, go to **Settings > Storefront** and copy the snippet under **Product cards and header**. In the theme's **Edit code**, add a snippet named `loveful-wishlist`, paste and save. It holds your store's metafield namespace, and renders [card hearts](https://docs.loveful.app/developers/guides/card-hearts.md) and a [header link](https://docs.loveful.app/developers/guides/header-link.md).

**3. Drop in an element**

Put a save button anywhere on a product template:

```liquid theme={null}
<loveful-button
  variant-id="{{ product.selected_or_first_available_variant.id }}"
  data-product-id="{{ product.id }}"
  data-handle="{{ product.handle }}"
  data-title="{{ product.title | escape }}"
  role="button"
  tabindex="0"
>Save to wishlist</loveful-button>
```

**4. Listen for saves**

```js theme={null}
window.loveful?.addEventListener("item_added", (e) => {
  console.log("Saved", e.detail.snapshot.title);
});
```

For a script that may run before Loveful's, see [Waiting for the bus](https://docs.loveful.app/developers/javascript-api.md#waiting-for-the-bus).

## Guides

> [card] [Hearts on your product cards](https://docs.loveful.app/developers/guides/card-hearts.md)
>
> The snippet's heart, or your own markup.

> [card] [Header wishlist link](https://docs.loveful.app/developers/guides/header-link.md)
>
> A link with a live count of saved items.

> [card] [React to saves](https://docs.loveful.app/developers/guides/react-to-saves.md)
>
> Toasts, theme badges and analytics from wishlist events.

> [card] [Restyle with CSS variables](https://docs.loveful.app/developers/guides/restyle.md)
>
> Match Loveful's elements to your theme.

Ready-made snippets are on [Examples](https://docs.loveful.app/developers/examples.md).

## What you can't do from the theme

* **Save or remove from script.** The bus has no add or remove method: saves go through a [`<loveful-button>`](https://docs.loveful.app/developers/web-components#loveful-button) the shopper clicks, and removes through it or a wishlist card's remove control. [`clear()`](https://docs.loveful.app/developers/javascript-api#clear) empties a whole list.
* **Render Loveful's own snippets.** `loveful-card` and `loveful-icon` belong to the app's blocks, and Shopify doesn't let a theme render them. Write your own card markup for [`<loveful-list>`](https://docs.loveful.app/developers/web-components#loveful-list).
* **Read other shoppers' lists.** Only the signed-in shopper's own list, and lists shared by link, are available on the storefront. For everything else, use [webhooks](https://docs.loveful.app/developers/webhooks.md).


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