Shopify Liquid Templating: A Practical Tutorial for Developers
Learn Shopify Liquid from the ground up with practical examples covering objects, filters, tags, sections, and performance patterns for production themes.
Shopify Liquid Templating: A Practical Tutorial for Developers
6 min read
Shopify Liquid Templating: A Practical Tutorial for Developers
Liquid is the templating language that powers every Shopify Online Store theme. Whether you are building a theme from scratch, customizing an existing one, or debugging a client's storefront, Liquid fluency is essential. Unlike general-purpose programming languages, Liquid is intentionally sandboxed. It cannot execute arbitrary code, access the file system, or make network requests. This safety model makes it reliable for multi-tenant hosting but also means you need to think differently about solving problems.
This tutorial progresses from fundamentals to production-grade patterns. If you have programmed in any language before, you will be productive in Liquid within an afternoon.
Liquid fundamentals
Liquid uses two types of delimiters:
- Output tags render a value to the page. Example:
product.titleoutputs the product name. - Logic tags control flow without producing output. Example:
if product.availablestarts a conditional block.
Objects and properties
Shopify exposes a rich set of global objects. The most commonly used are:
product. The current product with properties like title, description, price, variants, images, tags, and metafields.collection. A group of products with title, products, sort_by, and filters.cart. The shopping cart with items, total_price, item_count, and note.customer. The logged-in customer (null for guests) with email, orders, tags, and addresses.shop. Store-level data like name, url, currency, and money_format.request. The current HTTP request with locale, page_type, and path.
Access nested properties with dot notation: product.featured_image.src.
Filters
Filters transform output values and are chained with the pipe character. Shopify adds commerce-specific filters beyond standard Liquid:
moneyandmoney_with_currency. Format prices using the store's currency settings.img_url. Generate responsive image URLs with size parameters.asset_urlandasset_img_url. Reference files in the theme's assets directory.link_toandurl_for. Generate anchor tags and URLs for routes, products, and collections.strip_html. Remove HTML tags from rich text content.truncatewords. Limit text to a specified number of words.
Control flow
Liquid supports standard conditional and iteration constructs:
if,elsif,else,endif. Conditional rendering based on truthiness.unless,endunless. Inverse conditional, useful for guard clauses.for,endfor. Iterate over arrays with access toforloop.index,forloop.first, andforloop.last.case,when,endcase. Switch-style matching for cleaner multi-branch logic.
Sections and blocks: the building blocks of Online Store 2.0
Sections are modular, reusable Liquid components that merchants can rearrange in the theme editor. Every modern Shopify theme is built around sections.
Section anatomy
A section file lives in sections/ and contains three parts:
- Liquid template. The HTML and Liquid logic that renders the section.
- CSS and JavaScript. Optional inline styles and scripts scoped to the section.
- Schema. A JSON block that defines settings, blocks, and presets for the theme editor.
The schema is where you define the merchant-facing configuration: collection pickers, range sliders, color selectors, and text inputs that populate section settings.
Blocks
Blocks are repeatable sub-components within a section. They let merchants add, remove, and reorder content units. Common block types include headings, text paragraphs, buttons, images, and product cards.
Each block gets a shopify_attributes property that you should render on the wrapper element to enable theme editor click-to-select functionality.
Snippets and the render tag
Snippets are partial templates stored in snippets/. Use the render tag (not the deprecated include tag) to invoke them.
Key differences from include:
rendercreates an isolated scope. The snippet cannot access outer variables unless you explicitly pass them.- This isolation prevents naming collisions and makes snippets safer to reuse across sections.
- You cannot use
assignorcaptureto send data back to the parent template from a rendered snippet.
Name your snippets with a component-style convention: product-card, collection-filter, icon-chevron. This makes the snippets/ directory navigable as the theme grows.
Metafields: extending Shopify data
Metafields let you attach custom data to products, collections, customers, and orders. In Liquid, access them through the metafields namespace on the parent object.
For simple values (single-line text, numbers, booleans), the metafield value renders directly. For complex data (JSON metafields, metafield lists, file references), you may need to iterate or parse the structured content.
Best practices for metafields in themes:
- Define metafield definitions in Shopify admin so merchants get a structured input UI instead of raw JSON.
- Use typed metafields (color, dimension, rating, date) when possible. Shopify provides native rendering support.
- Gate rendering on metafield existence to avoid blank output when the metafield has not been populated.
Performance patterns for production themes
Liquid executes server-side on every request, so inefficient templates directly increase time to first byte. Follow these patterns:
- Avoid nested for loops on large collections. If you need to cross-reference products and tags, pre-compute the mapping in a metafield or use the Section Rendering API to load data asynchronously.
- Use
renderinstead ofinclude. Beyond scope isolation,renderis cacheable by Shopify's rendering engine. - Limit Liquid output in JSON templates. For headless or AJAX patterns, use
.jsontemplates with minimal Liquid to produce structured data rather than HTML. - Minimize conditional checks per product. Move complex logic into metafields or tags so the Liquid template performs a simple lookup rather than a chain of conditionals.
- Leverage lazy loading for images. Use the
loading="lazy"attribute on images below the fold andfetchpriority="high"on the hero image. - Preload critical assets. Use the
preloadlink tag for above-the-fold stylesheets and fonts.
Debugging Liquid
- Shopify Theme Inspector. A Chrome extension that overlays render times on each Liquid section. Indispensable for finding slow templates.
- JSON output. Dump any object as JSON to inspect its structure during development. Remove these before shipping.
- Theme Check. A linter that catches Liquid anti-patterns, deprecated tags, and missing translations. Run it in CI with
shopify theme check. - Development store preview. Always test on a development store with representative data volume. A theme that renders fast with 10 products may crawl with 10,000.
Common pitfalls
- Using
includeinstead ofrender. Theincludetag is deprecated and creates shared scope that leads to subtle bugs. - Forgetting pagination. Collection pages default to 50 products. Use the
paginatetag to control page size and render pagination controls. - Hardcoding strings. Always use translation keys via the
tfilter for customer-facing text. This makes your theme translation-ready from day one. - Ignoring the 10-second render limit. Shopify terminates Liquid rendering after 10 seconds. Complex logic on large datasets can hit this limit.
Final thoughts
Liquid may feel limited compared to a full programming language, but those limitations are a feature. They enforce clean data flow, encourage modular design, and keep themes fast. Master sections, snippets, metafields, and the performance patterns above, and you will be able to build any storefront experience a Shopify Plus merchant needs. If you run into an edge case that Liquid cannot handle, reach for a theme app extension or a custom app. We are happy to help you scope that boundary.
Stay Updated
Get Shopify build, conversion, and growth notes when we have something useful to share. We’ll ask you to confirm your email before sending anything else.
Useful Shopify notes, sent only when we have something worth sharing.
Mateo Alvarez
Lead Performance Engineer
Heads the theme engineering team at madeforshopify with deep expertise in Liquid performance and Online Store 2.0 architecture.
Related Posts
View AllShopify Plus Checkout Customization: Best Practices for 2025
5 min
Shopify Plus Checkout Customization: Best Practices for 2025
Master checkout extensibility on Shopify Plus with proven patterns for upsells, branding, validation, and payment customization that protect conversion rates.
Conversion Rate Optimization for Shopify Stores: A Data-Driven Playbook
5 min
Conversion Rate Optimization for Shopify Stores: A Data-Driven Playbook
Learn the CRO framework we use to systematically lift conversion rates on Shopify Plus stores through experimentation, analytics, and UX improvements.
Headless Shopify: When and Why to Go Headless
5 min
Headless Shopify: When and Why to Go Headless
Learn the business triggers, technical considerations, and launch blueprint for a high-performing headless Shopify architecture.