Shopify Liquid Templates

VerifiedSafe

This skill provides best practices for Liquid templates in Shopify themes: snippet structure using the render tag, clean logic flow with the {% liquid %} tag, responsive image handling via image_tag, and inline SVG inclusion using inline_asset_content. It helps when creating or modifying Liquid templates to ensure performance, readability, and adherence to Shopify's recommended approaches.

Sby Skills Guide Bot
DevelopmentIntermediate
6/2/2026
Claude Code
#shopify#liquid#templates#snippets#images

Recommended for

Automated summary

Provides best practices for writing Liquid templates in Shopify themes, covering snippets, logic, image handling, and SVG usage.

Strengths

  • Emphasizes modern `render` over `include` for better performance
  • Promotes `image_tag` with responsive images and lazy loading
  • Encourages clean logic structuring with the `{% liquid %}` tag
  • Includes recommendations for proper SVG integration

Limitations

  • Focuses only on Shopify Liquid, not general Liquid
  • Does not cover advanced metafield or section schema
  • Can be opinionated on specific coding patterns
When to use it

Ideal when creating or refactoring Shopify theme templates to ensure performance and maintainability.

When not to use it

Not suitable for non-Shopify Liquid projects or for basic template work that does not require these optimizations.

Security analysis

Safe
Quality score92/100

The skill contains only template code snippets and guidelines for Shopify Liquid; no executable commands, destructive operations, or sensitive data handling.

No concerns found

How this analysis is made

Examples

Create a product card snippet
Create a reusable 'product-card' snippet using Liquid render, with parameters for product, show_price, and image_size. Follow best practices: use render, image_tag with responsive widths, and clean logic.
Optimize image handling in a template
Refactor the image handling in my Shopify theme's product template to use image_tag with srcset and lazy loading. Replace hardcoded img tags.
Convert SVG from inline to asset
I have raw SVG markup in my theme template. Rewrite it to use inline_asset_content with SVG files stored in the assets directory.

name: theme-shopify-liquid-templates description: Liquid template best practices for Shopify themes - snippets, logic, image handling, and SVG usage. Use when writing or modifying Liquid templates in Shopify themes.

Shopify Liquid Templates

Best practices for Liquid templates, snippets, logic flow, image handling, and SVG usage in Shopify themes.

When to Use

  • Creating or modifying Liquid templates
  • Working with snippets
  • Handling images and media
  • Writing Liquid logic
  • Using SVG icons

Snippets

Usage

  • Use {% render %} only (never include)
  • Inside each snippet, add a Usage block at the top

Snippet Structure

{%- comment -%}
Usage:
{% render 'snippet-name', param: value, another_param: value %}
{%- endcomment -%}

<div class="snippet-name">
  {{ param }}
</div>

Snippet Parameters

Pass data to snippets via parameters:

{% render 'product-card', 
  product: product, 
  show_price: true, 
  image_size: 'large' %}

Why render Instead of include

  • render is more performant
  • Better variable scoping
  • Recommended by Shopify

Liquid Logic

Use {% liquid %} Tag

For long or complex logic, use the {% liquid %} tag:

{% 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
%}

Logic Best Practices

  • Avoid deeply nested conditionals
  • Prefer readable, linear logic
  • Break complex logic into multiple liquid blocks if needed
  • Use meaningful variable names

Example: Clean Logic Flow

{% 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>

Images

Always Use image_tag

  • Always use image_tag filter
  • Use responsive srcset and sizes
  • Do NOT hardcode <img> tags
  • Use <image_url> to generate a URL for an image.
  • Always specify either a width or height parameter for <image_url>.

Image Tag Syntax

{{ image | image_url: width: image.width | image_tag: widths: '360, 720, 1080', loading: 'lazy' }}

Responsive Images

{% 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 Settings

Common image_tag parameters:

  • widths: Comma-separated list of widths for srcset
  • sizes: Sizes attribute for responsive images
  • loading: 'lazy' or 'eager'
  • alt: Alt text (use | escape filter)

SVG Files

Inline SVGs

Inline SVGs using the inline_asset_content filter:

{{ 'icon-arrow.svg' | inline_asset_content }}

Do NOT Paste Raw SVG

  • Do NOT paste raw SVG markup into templates
  • Store SVG files in assets/ directory
  • Use inline_asset_content filter to include them

SVG Example

<button class="icon-button">
  {{ 'icon-close.svg' | inline_asset_content }}
  <span class="visually-hidden">Close</span>
</button>

SVG Styling

SVGs can be styled with CSS when inlined:

.icon-button svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

Shopify Theme Documentation

Reference these official Shopify resources:

Common Liquid Patterns

Product Card Snippet

{%- 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>

Conditional Rendering

{% 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 %}

Instructions

  1. Use render for snippets, never include
  2. Add Usage comments to all snippets
  3. Use liquid tag for complex logic
  4. Always use image_tag - never hardcode <img>
  5. Inline SVGs using inline_asset_content filter
  6. Keep logic linear - avoid deep nesting
  7. Use responsive images with proper srcset and sizes

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/shopify-liquid-templates-mmio71za/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/shopify-liquid-templates-mmio71za' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/shopify-liquid-templates-mmio71za/download' --output '.skill-downloads/shopify-liquid-templates-mmio71za/SKILL.md.part' && mv '.skill-downloads/shopify-liquid-templates-mmio71za/SKILL.md.part' '.skill-downloads/shopify-liquid-templates-mmio71za/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/shopify-liquid-templates-mmio71za/SKILL.md' && test -s '.skill-downloads/shopify-liquid-templates-mmio71za/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/theme-shopify-liquid-templates' && cp -R '.skill-downloads/shopify-liquid-templates-mmio71za' '.claude/skills/theme-shopify-liquid-templates'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/shopify-liquid-templates-mmio71za'

openskills read 'shopify-liquid-templates-mmio71za'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/shopify-liquid-templates-mmio71za/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills