home / skills / toilahuongg / shopify-agents-kit / shopify-liquid

shopify-liquid skill

/.claude/skills/shopify-liquid

This skill helps you implement Shopify Liquid in Theme App Extensions and Themes by guiding syntax, schema use, and data access for dynamic storefronts.

npx playbooks add skill toilahuongg/shopify-agents-kit --skill shopify-liquid

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
2.7 KB
---
name: shopify-liquid
description: Guide for using the Liquid template language within Shopify Theme App Extensions and Themes. Use this skill when building App Embed Blocks, App Blocks, or modifying Shopify Themes.
---

# Shopify Liquid Skill

Liquid is the template language used by Shopify to load dynamic content on storefronts.

## 1. Core Syntax

-   **Output**: `{{ ... }}` - Prints content to the page.
-   **Tags**: `{% ... %}` - Logic (if, for, assign).
-   **Filters**: `{{ value | filter }}` - Modifies output.

## 2. Theme App Extensions (App Blocks)

Modern apps inject code into themes using **App Blocks**, avoiding direct legacy code edits.

### `schema` Tag
Defines settings available in the Theme Editor.

```liquid
{% schema %}
{
  "name": "Star Rating",
  "target": "section",
  "settings": [
    {
      "type": "color",
      "id": "star_color",
      "label": "Star Color",
      "default": "#ff0000"
    }
  ]
}
{% endschema %}
```

### Accessing Settings
Use `block.settings.id` to access values defined in schema.

```liquid
<div style="color: {{ block.settings.star_color }}">
  ★★★★★
</div>
```

### App Embed Blocks
Scripts that run globally (e.g., analytics, chat bubbles).

```liquid
{% schema %}
{
  "name": "Chat Bubble",
  "target": "body",
  "javascript": "chat.js",
  "settings": []
}
{% endschema %}
```

## 3. Common Objects

-   **`product`**:
    -   `{{ product.title }}`
    -   `{{ product.variants.first.id }}`
    -   `{{ product.featured_image | image_url: width: 400 }}`
-   **`cart`**:
    -   `{{ cart.item_count }}`
    -   `{{ cart.currency.iso_code }}`
-   **`customer`**:
    -   `{% if customer %}` checks if logged in.
-   **`shop`**:
    -   `{{ shop.name }}`
    -   `{{ shop.permanent_domain }}`

## 4. Useful Filters

-   **Money**: `{{ product.price | money }}` -> `$10.00`
-   **Asset URL**: `{{ 'style.css' | asset_url }}` (Reference assets in `assets/` folder)
-   **JSON**: `{{ product | json }}` (Useful for passing data to JS)

## 5. Using with JavaScript

Pass Liquid data to JavaScript using data attributes or global variables.

**Pattern: Data Attributes (Preferred)**
```liquid
<div id="my-app" data-product-id="{{ product.id }}" data-shop="{{ shop.permanent_domain }}"></div>

<script>
  const app = document.getElementById('my-app');
  const productId = app.dataset.productId;
</script>
```

**Pattern: Global Object (Legacy)**
```liquid
<script>
  window.ShopifyData = {
    product: {{ product | json }},
    cart: {{ cart | json }}
  };
</script>
```

## 6. App Proxies
When the request comes from an App Proxy, `liquid` renders the response before sending it to the layout.

-   If you return `Content-Type: application/liquid`, Shopify will parse the Liquid in your response.

Overview

This skill is a concise guide for using the Liquid template language inside Shopify Theme App Extensions and Themes. It focuses on practical patterns for App Blocks, App Embed Blocks, theme edits, and passing Liquid data to JavaScript. Use it to implement dynamic storefront features without breaking core theme code.

How this skill works

It explains Liquid's core primitives: output ({{ }}), tags ({% %}) for logic, and filters to transform values. The skill covers Theme App Extension patterns (schema, block.settings), common global objects (product, cart, customer, shop), useful filters (money, asset_url, json), and recommended ways to surface Liquid data to client-side JavaScript. It also outlines App Proxy behavior and when Shopify parses Liquid returned from a proxy.

When to use it

  • Building or configuring App Blocks and App Embed Blocks for themes
  • Adding dynamic storefront content like product snippets or cart widgets
  • Passing server-rendered data to client-side scripts safely
  • Creating Theme Editor settings using the schema block
  • Implementing app proxies that return Liquid-parsed responses

Best practices

  • Define settings in a {% schema %} block and read values with block.settings.id to keep editor controls consistent
  • Prefer data attributes for passing Liquid to JavaScript (data-*), avoid embedding large JSON on window objects
  • Use filters like money, asset_url, and json to format values for display or consumption by scripts
  • Scope App Blocks to avoid editing legacy theme templates directly—use target in schema to attach blocks safely
  • Check for objects (e.g., {% if customer %}) before accessing properties to prevent errors in templates

Example use cases

  • Create a Star Rating App Block with editable color using schema and block.settings.star_color
  • Add a global chat or analytics script as an App Embed Block targeting body with a javascript file
  • Render product metadata into a DOM element via data attributes for a quick client-side widget
  • Return Liquid from an App Proxy with Content-Type: application/liquid so Shopify renders it within the storefront layout
  • Use product | json to pass product data into a lightweight front-end picker component

FAQ

How do I expose Theme Editor settings to my block?

Declare a {% schema %} JSON block with settings and read values via block.settings.<id> inside your block markup.

What is the recommended way to pass Liquid data to JavaScript?

Prefer data attributes (data-*) on elements and read them via element.dataset; use product | json sparingly for structured data when needed.