Loading...
Loading...
HTML structure, data attributes, and commenting guidelines for Shopify themes. Use when structuring HTML markup and adding comments to Shopify theme code.
npx skill4agent add skomskiy/shopify-cursor-skills shopify-html-data-comments<product-card data-product-id="{{ product.id }}">
<!-- Content -->
</product-card>data-*dataset<!-- Good - kebab-case -->
<div
data-product-id="{{ product.id }}"
data-variant-id="{{ variant.id }}"
data-product-handle="{{ product.handle }}">
</div>
<!-- Bad - camelCase or other formats -->
<div data-productId="{{ product.id }}"></div>class ProductCard extends HTMLElement {
constructor() {
super();
this.productId = this.dataset.productId;
this.variantId = this.dataset.variantId;
this.productHandle = this.dataset.productHandle;
}
}<image-gallery
data-autoplay="{{ section.settings.autoplay }}"
data-interval="{{ section.settings.interval }}"
data-transition="{{ section.settings.transition }}">
<!-- Gallery content -->
</image-gallery>class ImageGallery extends HTMLElement {
constructor() {
super();
this.autoplay = this.dataset.autoplay === 'true';
this.interval = parseInt(this.dataset.interval, 10);
this.transition = this.dataset.transition;
}
}{%- comment -%}
Calculate discount percentage for products with compare_at_price.
Only show discount badge if discount is greater than 20%.
{%- endcomment -%}
{% liquid
if product.compare_at_price > product.price
assign discount = product.compare_at_price | minus: product.price
assign discount_percent = discount | times: 100 | divided_by: product.compare_at_price
if discount_percent > 20
assign show_badge = true
endif
endif
%}{%- comment -%}
Usage:
{% render 'product-card',
product: product,
show_vendor: true,
show_price: true %}
{%- endcomment -%}{%- comment -%}
Product Card Section
Displays product information with image, title, price, and add to cart button
{%- endcomment -%}
<div class="product-card">
<!-- Product Image -->
<div class="product-card__image">
{{ product.featured_image | image_tag: widths: '360, 720', loading: 'lazy' }}
</div>
<!-- Product Info -->
<div class="product-card__info">
<h3 class="product-card__title">{{ product.title }}</h3>
<p class="product-card__price">{{ product.price | money }}</p>
</div>
</div>{% if product.available %}{%- comment -%}
Good: Explains why, not what
Calculate discount percentage. Shopify doesn't provide this directly,
so we calculate it from compare_at_price and current price.
{%- endcomment -%}
{% liquid
assign discount = product.compare_at_price | minus: product.price
assign discount_percent = discount | times: 100 | divided_by: product.compare_at_price
%}
{%- comment -%}
Bad: Explains what, which is obvious
Check if product is available. If available, show add to cart button.
{%- endcomment -%}
{% if product.available %}
<button>Add to Cart</button>
{% endif %}<article class="product-card">
<header class="product-card__header">
<h2 class="product-card__title">{{ product.title }}</h2>
</header>
<div class="product-card__image">
{{ product.featured_image | image_tag: widths: '360, 720', loading: 'lazy' }}
</div>
<footer class="product-card__footer">
<p class="product-card__price">{{ product.price | money }}</p>
<button class="product-card__button">Add to Cart</button>
</footer>
</article><button
aria-label="Add {{ product.title }} to cart"
data-product-id="{{ product.id }}">
Add to Cart
</button>data-*