ワンクリックで
shopify-liquid-fundamentals
Core Shopify Liquid templating best practices for performance, maintainability, and clean code
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Core Shopify Liquid templating best practices for performance, maintainability, and clean code
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Prisma ORM best practices for Shopify apps including multi-tenant data isolation, query optimization, transaction patterns, and migration strategies. Auto-invoked when working with database operations.
Build consistent UI using Polaris Web Components patterns for common page layouts like index pages, detail pages, forms, and empty states. Use this skill when creating new pages or refactoring existing UI components.
Common Shopify Admin GraphQL API patterns for product queries, metafield operations, webhooks, and bulk operations. Auto-invoked when working with Shopify API integration.
Polaris composition patterns and page templates for common Shopify app layouts. Provides index tables, settings pages, dashboards, and resource management patterns. Auto-invoked when building page layouts.
Core Polaris Web Components fundamentals including component library structure, design tokens, responsive patterns, and SSR compatibility. Auto-invoked when working with Polaris components.
Internationalization fundamentals for multi-language Shopify themes
| name | Shopify Liquid Fundamentals |
| description | Core Shopify Liquid templating best practices for performance, maintainability, and clean code |
{%- -%} to trim whitespace around Liquid tags{% render %} over deprecated {% include %}{% liquid %} for multi-line logic blocksExample:
{%- liquid
assign product_available = product.available | default: false
assign product_price = product.price | default: 0
if product == blank
assign error_message = 'Product not found'
endif
-%}
assign for complex calculations instead of inline logicGood:
{%- assign discounted_price = product.price | times: 0.9 | money -%}
<p>Sale: {{ discounted_price }}</p>
Bad:
<p>Sale: {{ product.price | times: 0.9 | money }}</p>
<p>Save: {{ product.price | times: 0.1 | money }}</p>
Always provide defaults and handle empty states:
{%- liquid
assign heading = section.settings.heading | default: 'Default Heading'
assign show_vendor = section.settings.show_vendor | default: false
if product == blank
assign error_message = 'Product unavailable'
endif
-%}
{%- if error_message -%}
<p class="error">{{ error_message }}</p>
{%- else -%}
<!-- Normal content -->
{%- endif -%}
{{ variable }} # Output variable
{{ variable | escape }} # Escape HTML
{{ variable | default: 'fallback' }} # Provide default
{{- variable -}} # Trim whitespace
{% if condition %}
{% elsif other_condition %}
{% else %}
{% endif %}
{% unless condition %}
{% endunless %}
{% case variable %}
{% when 'value1' %}
{% when 'value2' %}
{% else %}
{% endcase %}
{% for item in collection %}
{{ item.title }}
{% endfor %}
{% for item in collection limit: 4 %}
{{ item.title }}
{% endfor %}
{% for i in (1..5) %}
Item {{ i }}
{% endfor %}
{% assign name = 'value' %}
{% capture variable %}
Content here
{% endcapture %}
{{ 'hello' | capitalize }} # Hello
{{ 'HELLO' | downcase }} # hello
{{ 'hello' | upcase }} # HELLO
{{ 'hello world' | truncate: 8 }} # hello...
{{ '<p>test</p>' | escape }} # <p>test</p>
{{ 'hello world' | remove: 'world' }} # hello
{{ 'hello' | append: ' world' }} # hello world
{{ collection | size }} # Number of items
{{ collection | first }} # First item
{{ collection | last }} # Last item
{{ collection | join: ', ' }} # Join with comma
{{ collection | reverse }} # Reverse order
{{ collection | sort: 'title' }} # Sort by property
{{ 10 | plus: 5 }} # 15
{{ 10 | minus: 5 }} # 5
{{ 10 | times: 5 }} # 50
{{ 10 | divided_by: 5 }} # 2
{{ 10.5 | ceil }} # 11
{{ 10.5 | floor }} # 10
{{ 10.5 | round }} # 11
{{ 1000 | money }} # $10.00
{{ 1000 | money_with_currency }} # $10.00 USD
{{ 1000 | money_without_currency }} # 10.00
{{ image | image_url: width: 400 }}
{{ image | image_url: width: 400, height: 400 }}
{{ image | image_tag }}
{{ image | image_tag: alt: 'Description' }}
{{ shop.name }} # Store name
{{ shop.email }} # Store email
{{ cart.item_count }} # Cart items
{{ customer.name }} # Customer name (if logged in)
{{ settings.color_primary }} # Theme setting
{{ product.title }}
{{ product.price }}
{{ product.compare_at_price }}
{{ product.available }}
{{ product.vendor }}
{{ product.type }}
{{ product.featured_image }}
{{ product.url }}
{{ collection.title }}
{{ collection.description }}
{{ collection.products }}
{{ collection.products_count }}
{{ collection.url }}
<h1>{{ product.title | escape }}</h1>
<p>{{ customer.name | escape }}</p>
{%- assign heading = section.settings.heading | default: 'Default Title' -%}
{%- assign image = product.featured_image | default: blank -%}
{%- if heading != blank -%}
<h2>{{ heading | escape }}</h2>
{%- endif -%}
{%- liquid
assign is_sale = false
if product.compare_at_price > product.price
assign is_sale = true
endif
assign discount_percent = product.compare_at_price | minus: product.price | times: 100 | divided_by: product.compare_at_price
-%}
{%- # Bad -%}
{% if product.available %}
{% if product.compare_at_price > product.price %}
<span>On Sale</span>
{% endif %}
{% endif %}
{%- # Good -%}
{%- liquid
assign is_on_sale = false
if product.available and product.compare_at_price > product.price
assign is_on_sale = true
endif
-%}
{%- if is_on_sale -%}
<span>On Sale</span>
{%- endif -%}
<div class="product{% if product.available %} in-stock{% else %} out-of-stock{% endif %}">
<!-- Content -->
</div>
{%- for product in collection.products -%}
<div class="product-{{ forloop.index }}">
{%- if forloop.first -%}
<span>Featured</span>
{%- endif -%}
{{ product.title }}
</div>
{%- endfor -%}
{%- if collection.products.size > 0 -%}
{%- for product in collection.products -%}
<!-- Product markup -->
{%- endfor -%}
{%- else -%}
<p>No products available.</p>
{%- endif -%}
{%- if product.featured_image -%}
<img
srcset="
{{ product.featured_image | image_url: width: 400 }} 400w,
{{ product.featured_image | image_url: width: 800 }} 800w,
{{ product.featured_image | image_url: width: 1200 }} 1200w
"
sizes="(min-width: 1024px) 33vw, (min-width: 768px) 50vw, 100vw"
src="{{ product.featured_image | image_url: width: 800 }}"
alt="{{ product.featured_image.alt | escape }}"
loading="lazy"
width="800"
height="{{ 800 | divided_by: product.featured_image.aspect_ratio | ceil }}"
>
{%- endif -%}
{% render 'product-card' %}
{% render 'product-card', product: product, show_vendor: true %}
{% render 'button',
text: 'Add to Cart',
url: product.url,
style: 'primary',
size: 'large'
%}
limit parameter when possible❌ Don't repeat expensive operations:
<p>{{ product.price | times: 1.1 | money }}</p>
<p>{{ product.price | times: 1.1 | money }}</p>
✅ Do assign to variable:
{%- assign price_with_tax = product.price | times: 1.1 | money -%}
<p>{{ price_with_tax }}</p>
<p>{{ price_with_tax }}</p>
❌ Don't forget to escape:
<h1>{{ product.title }}</h1>
✅ Do escape user input:
<h1>{{ product.title | escape }}</h1>
❌ Don't use deprecated include:
{% include 'snippet-name' %}
✅ Do use render:
{% render 'snippet-name' %}
Follow these fundamentals for clean, performant, maintainable Shopify Liquid code.