Loading...
Loading...
Liquid template best practices for Shopify themes - snippets, logic, image handling, and SVG usage. Use when writing or modifying Liquid templates in Shopify themes.
npx skill4agent add niccos-shopify-workspace/shopify-cursor-skills theme-shopify-liquid-templates{% render %}include{%- comment -%}
Usage:
{% render 'snippet-name', param: value, another_param: value %}
{%- endcomment -%}
<div class="snippet-name">
{{ param }}
</div>{% render 'product-card',
product: product,
show_price: true,
image_size: 'large' %}renderincluderender{% liquid %}{% liquid %}{% liquid
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 is_big_discount = true
endif
%}liquid{% liquid
if product.available
assign button_text = 'Add to Cart'
assign button_class = 'btn--primary'
else
assign button_text = 'Sold Out'
assign button_class = 'btn--disabled'
endif
%}
<button class="{{ button_class }}">
{{ button_text }}
</button>image_tagimage_tagsrcset<img><image_url><image_url>{{ image | image_url: width: image.width | image_tag: widths: '360, 720, 1080', loading: 'lazy' }}{% assign image_widths = '360, 540, 720, 900, 1080, 1296, 1512, 1728, 1944, 2160' %}
{{ product.featured_image | image_url: width: product.featured_image.width | image_tag:
widths: image_widths,
sizes: '(min-width: 1200px) 50vw, 100vw',
loading: 'lazy',
alt: product.featured_image.alt | escape }}image_tagwidthssizesloadingalt| escapeinline_asset_content{{ 'icon-arrow.svg' | inline_asset_content }}assets/inline_asset_content<button class="icon-button">
{{ 'icon-close.svg' | inline_asset_content }}
<span class="visually-hidden">Close</span>
</button>.icon-button svg {
width: 24px;
height: 24px;
fill: currentColor;
}{%- comment -%}
Usage:
{% render 'product-card', product: product, show_vendor: false %}
{%- endcomment -%}
<div class="product-card">
<a href="{{ product.url }}">
{{ product.featured_image | image_tag: widths: '360, 720', loading: 'lazy' }}
<h3>{{ product.title }}</h3>
<p>{{ product.price | money }}</p>
</a>
</div>{% liquid
if section.settings.show_title
assign title_visible = true
else
assign title_visible = false
endif
%}
{% if title_visible %}
<h2>{{ section.settings.title }}</h2>
{% endif %}renderincludeliquidimage_tag<img>inline_asset_content