shopify-liquid-themes
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseShopify Liquid Themes
Shopify Liquid 主题
Theme Architecture
主题架构
.
├── sections/ # Full-width page modules with {% schema %} — hero, product grid, testimonials
├── blocks/ # Nestable components with {% schema %} — slides, feature items, text blocks
├── snippets/ # Reusable fragments via {% render %} — buttons, icons, image helpers
├── layout/ # Page wrappers (must include {{ content_for_header }} and {{ content_for_layout }})
├── templates/ # JSON files defining which sections appear on each page type
├── config/ # Global theme settings (settings_schema.json, settings_data.json)
├── locales/ # Translation files (en.default.json, fr.json, etc.)
└── assets/ # Static CSS, JS, images (prefer {% stylesheet %}/{% javascript %} instead).
├── sections/ # 带有{% schema %}的全宽页面模块 — 首页横幅、产品网格、客户评价
├── blocks/ # 带有{% schema %}的可嵌套组件 — 轮播图、功能项、文本块
├── snippets/ # 可通过{% render %}调用的可复用片段 — 按钮、图标、图片工具
├── layout/ # 页面包装器(必须包含{{ content_for_header }}和{{ content_for_layout }})
├── templates/ # 定义各页面类型显示哪些sections的JSON文件
├── config/ # 全局主题设置(settings_schema.json、settings_data.json)
├── locales/ # 翻译文件(en.default.json、fr.json等)
└── assets/ # 静态CSS、JS、图片资源(优先使用{% stylesheet %}/{% javascript %}标签)When to use what
适用场景对比
| Need | Use | Why |
|---|---|---|
| Full-width customizable module | Section | Has |
| Small nestable component with editor settings | Block | Has |
| Reusable logic, not editable by merchant | Snippet | No schema, rendered via |
| Logic shared across blocks/snippets | Snippet | Blocks can't |
| 需求 | 使用对象 | 原因 |
|---|---|---|
| 全宽可自定义模块 | Section | 包含 |
| 带编辑器设置的小型可嵌套组件 | Block | 包含 |
| 不可被商家编辑的可复用逻辑 | Snippet | 无schema,通过 |
| blocks/snippets间共享的逻辑 | Snippet | blocks无法通过 |
Liquid Syntax
Liquid 语法
Delimiters
分隔符
- — Output (prints a value)
{{ ... }} - — Output with whitespace trimming
{{- ... -}} - — Logic tag (if, for, assign) — prints nothing
{% ... %} - — Logic tag with whitespace trimming
{%- ... -%}
- — 输出(打印值)
{{ ... }} - — 去除前后空白的输出
{{- ... -}} - — 逻辑标签(if、for、assign)— 无输出
{% ... %} - — 去除前后空白的逻辑标签
{%- ... -%}
Operators
运算符
Comparison: , , , , ,
Logical: , ,
==!=><>=<=andorcontains比较运算符: , , , , ,
逻辑运算符: , ,
==!=><>=<=andorcontainsCritical Gotchas
关键注意事项
- No parentheses in conditions — use nested instead
{% if %} - No ternary — always use
{% if cond %}value{% else %}other{% endif %} - loops max 50 iterations — use
forfor larger arrays{% paginate %} - only works with strings — can't check objects in arrays
contains - /
{% stylesheet %}don't render Liquid — no Liquid inside them{% javascript %} - Snippets can't access outer-scope variables — pass them as render params
- is deprecated — always use
include{% render 'snippet_name' %} - tag — multi-line logic without delimiters; use
{% liquid %}for outputecho
- 条件判断中不支持括号 — 改用嵌套
{% if %} - 不支持三元表达式 — 始终使用
{% if cond %}value{% else %}other{% endif %} - 循环最多迭代50次 — 处理大型数组时使用
for{% paginate %} - 仅适用于字符串 — 无法检查数组中的对象
contains - /
{% stylesheet %}标签不解析Liquid — 标签内部不能写Liquid代码{% javascript %} - Snippets无法访问外部作用域变量 — 需通过render参数传递
- 已被弃用 — 始终使用
include{% render 'snippet_name' %} - 标签 — 无需分隔符的多行逻辑;使用
{% liquid %}进行输出echo
Variables
变量定义
liquid
{% assign my_var = 'value' %}
{% capture my_var %}computed {{ value }}{% endcapture %}
{% increment counter %}
{% decrement counter %}liquid
{% assign my_var = 'value' %}
{% capture my_var %}computed {{ value }}{% endcapture %}
{% increment counter %}
{% decrement counter %}Filter Quick Reference
过滤器速查
Filters are chained with . Output type of one filter feeds input of next.
|Array: , , , , , , , , , , , , , , , ,
String: , , , , , , , , , , , , , , , , , , ,
Math: , , , , , , , , , ,
Money: , , ,
Color: , , , , , , , , ,
Media: , , , , ,
URL: , , ,
HTML: , , , ,
Localization: (translate), ,
Other: , , , , , ,
compactconcatfindfind_indexfirsthasjoinlastmaprejectreversesizesortsort_naturalsumuniqwhereappendcapitalizedowncaseescapehandleizelstripnewline_to_brprependremovereplacerstripslicesplitstripstrip_htmltruncatetruncatewordsupcaseurl_decodeurl_encodeabsat_leastat_mostceildivided_byfloorminusmoduloplusroundtimesmoneymoney_with_currencymoney_without_currencymoney_without_trailing_zeroscolor_brightnesscolor_darkencolor_lightencolor_mixcolor_modifycolor_saturatecolor_desaturatecolor_to_hexcolor_to_hslcolor_to_rgbimage_urlimage_tagvideo_tagexternal_video_tagmedia_tagmodel_viewer_tagasset_urlasset_img_urlfile_urlshopify_asset_urllink_toscript_tagstylesheet_tagtime_tagplaceholder_svg_tagtformat_addresscurrency_selectordatedefaultjsonstructured_datafont_facefont_urlpayment_buttonFull details: language filters, HTML/media filters, commerce filters
过滤器通过链式调用,前一个过滤器的输出作为后一个的输入。
|数组类: , , , , , , , , , , , , , , , ,
字符串类: , , , , , , , , , , , , , , , , , , ,
数学类: , , , , , , , , , ,
金额类: , , ,
颜色类: , , , , , , , , ,
媒体类: , , , , ,
URL类: , , ,
HTML类: , , , ,
本地化类: (翻译), ,
其他类: , , , , , ,
compactconcatfindfind_indexfirsthasjoinlastmaprejectreversesizesortsort_naturalsumuniqwhereappendcapitalizedowncaseescapehandleizelstripnewline_to_brprependremovereplacerstripslicesplitstripstrip_htmltruncatetruncatewordsupcaseurl_decodeurl_encodeabsat_leastat_mostceildivided_byfloorminusmoduloplusroundtimesmoneymoney_with_currencymoney_without_currencymoney_without_trailing_zeroscolor_brightnesscolor_darkencolor_lightencolor_mixcolor_modifycolor_saturatecolor_desaturatecolor_to_hexcolor_to_hslcolor_to_rgbimage_urlimage_tagvideo_tagexternal_video_tagmedia_tagmodel_viewer_tagasset_urlasset_img_urlfile_urlshopify_asset_urllink_toscript_tagstylesheet_tagtime_tagplaceholder_svg_tagtformat_addresscurrency_selectordatedefaultjsonstructured_datafont_facefont_urlpayment_button详细说明:语言过滤器、HTML/媒体过滤器、电商过滤器
Tags Quick Reference
标签速查
| Category | Tags |
|---|---|
| Theme | |
| Control | |
| Iteration | |
| Variable | |
| HTML | |
| Documentation | |
Full details with syntax and parameters: references/tags.md
| 分类 | 标签 |
|---|---|
| 主题相关 | |
| 控制流 | |
| 循环迭代 | |
| 变量操作 | |
| HTML相关 | |
| 文档注释 | |
包含语法和参数的完整说明:references/tags.md
Objects Quick Reference
对象速查
Global objects (available everywhere)
全局对象(所有位置均可访问)
cartcollectionscustomerlocalizationpagesrequestroutessettingsshoptemplatethemelinklistsimagesblogsarticlesall_productsmetaobjectscanonical_urlcontent_for_headercontent_for_layoutpage_titlepage_descriptionhandlecurrent_pagecartcollectionscustomerlocalizationpagesrequestroutessettingsshoptemplatethemelinklistsimagesblogsarticlesall_productsmetaobjectscanonical_urlcontent_for_headercontent_for_layoutpage_titlepage_descriptionhandlecurrent_pagePage-specific objects
页面专属对象
| Template | Objects |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
Full reference: commerce objects, content objects, tier 2, tier 3
| 模板 | 对象 |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
完整参考:电商对象、内容对象、二级对象、三级对象
Schema Tag
Schema 标签
Sections and blocks require with a valid JSON object. Sections use , blocks use .
{% schema %}section.settings.*block.settings.*Sections和blocks必须包含标签及有效的JSON对象。Sections使用,blocks使用。
{% schema %}section.settings.*block.settings.*Section schema structure
Section schema 结构
json
{
"name": "t:sections.hero.name",
"tag": "section",
"class": "hero-section",
"limit": 1,
"settings": [],
"max_blocks": 16,
"blocks": [{ "type": "@theme" }],
"presets": [{ "name": "t:sections.hero.name" }],
"enabled_on": { "templates": ["index"] },
"disabled_on": { "templates": ["password"] }
}json
{
"name": "t:sections.hero.name",
"tag": "section",
"class": "hero-section",
"limit": 1,
"settings": [],
"max_blocks": 16,
"blocks": [{ "type": "@theme" }],
"presets": [{ "name": "t:sections.hero.name" }],
"enabled_on": { "templates": ["index"] },
"disabled_on": { "templates": ["password"] }
}Block schema structure
Block schema 结构
json
{
"name": "t:blocks.slide.name",
"tag": "div",
"class": "slide",
"settings": [],
"blocks": [{ "type": "@theme" }],
"presets": [{ "name": "t:blocks.slide.name" }]
}json
{
"name": "t:blocks.slide.name",
"tag": "div",
"class": "slide",
"settings": [],
"blocks": [{ "type": "@theme" }],
"presets": [{ "name": "t:blocks.slide.name" }]
}Setting type decision table
设置类型决策表
| Need | Setting Type | Key Fields |
|---|---|---|
| On/off toggle | | |
| Short text | | |
| Long text | | |
Rich text (with | | — |
Inline rich text (no | | — |
| Number input | | |
| Slider | | |
| Dropdown/segmented | | |
| Radio buttons | | |
| Text alignment | | |
| Color picker | | |
| Image upload | | — |
| Video upload | | — |
| External video URL | | |
| Product picker | | — |
| Collection picker | | — |
| Page picker | | — |
| Blog picker | | — |
| Article picker | | — |
| URL entry | | — |
| Menu picker | | — |
| Font picker | | |
| Editor header | | |
| Editor description | | |
| 需求 | 设置类型 | 关键字段 |
|---|---|---|
| 开关按钮 | | |
| 短文本输入 | | |
| 长文本输入 | | |
富文本(带 | | — |
行内富文本(无 | | — |
| 数字输入 | | |
| 滑块 | | |
| 下拉选择/分段选择 | | |
| 单选按钮 | | |
| 文本对齐 | | |
| 颜色选择器 | | |
| 图片上传 | | — |
| 视频上传 | | — |
| 外部视频URL | | |
| 产品选择器 | | — |
| 集合选择器 | | — |
| 页面选择器 | | — |
| 博客选择器 | | — |
| 文章选择器 | | — |
| URL输入 | | — |
| 菜单选择器 | | — |
| 字体选择器 | | |
| 编辑器标题 | | |
| 编辑器描述 | | |
visible_if
pattern
visible_ifvisible_if
模式
visible_ifjson
{
"visible_if": "{{ block.settings.layout == 'vertical' }}",
"type": "select",
"id": "alignment",
"label": "t:labels.alignment",
"options": [...]
}Conditionally shows/hides a setting in the editor based on other setting values.
json
{
"visible_if": "{{ block.settings.layout == 'vertical' }}",
"type": "select",
"id": "alignment",
"label": "t:labels.alignment",
"options": [...]
}根据其他设置值,在编辑器中条件显示/隐藏当前设置项。
Block entry types
Block 条目类型
- — Accept any theme block
{ "type": "@theme" } - — Accept app blocks
{ "type": "@app" } - — Accept only the
{ "type": "slide" }block typeslide
Full schema details and all 33 setting types: references/schema-and-settings.md
- — 支持任意主题block
{ "type": "@theme" } - — 支持应用block
{ "type": "@app" } - — 仅支持
{ "type": "slide" }类型的blockslide
完整schema说明及全部33种设置类型:references/schema-and-settings.md
CSS & JavaScript
CSS & JavaScript
Per-component styles and scripts
组件专属样式与脚本
Use and in sections, blocks, and snippets:
{% stylesheet %}{% javascript %}liquid
{% stylesheet %}
.my-component { display: flex; }
{% endstylesheet %}
{% javascript %}
console.log('loaded');
{% endjavascript %}- One tag each per file — multiple tags will error
{% stylesheet %} - No Liquid inside — these tags don't process Liquid; use CSS variables or classes instead
- Only supported in ,
sections/, andblocks/snippets/
在sections、blocks和snippets中使用和标签:
{% stylesheet %}{% javascript %}liquid
{% stylesheet %}
.my-component { display: flex; }
{% endstylesheet %}
{% javascript %}
console.log('loaded');
{% endjavascript %}- 每个文件仅允许一个对应标签 — 多个标签会报错
{% stylesheet %} - 标签内部不解析Liquid — 如需动态内容,改用CSS变量或类名
- 仅在、
sections/和blocks/目录中支持snippets/
{% style %}
tag (Liquid-aware CSS)
{% style %}{% style %}
标签(支持Liquid的CSS)
{% style %}For dynamic CSS that needs Liquid (e.g., color settings that live-update in editor):
liquid
{% style %}
.section-{{ section.id }} {
background: {{ section.settings.bg_color }};
}
{% endstyle %}用于需要Liquid的动态CSS(例如编辑器中实时更新的颜色设置):
liquid
{% style %}
.section-{{ section.id }} {
background: {{ section.settings.bg_color }};
}
{% endstyle %}CSS patterns for settings
基于设置的CSS模式
Single CSS property — use CSS variables:
liquid
<div style="--gap: {{ block.settings.gap }}px">Multiple CSS properties — use CSS classes as select values:
liquid
<div class="{{ block.settings.layout }}">单一CSS属性 — 使用CSS变量:
liquid
<div style="--gap: {{ block.settings.gap }}px">多个CSS属性 — 使用类名作为选择值:
liquid
<div class="{{ block.settings.layout }}">LiquidDoc ({% doc %}
)
{% doc %}LiquidDoc({% doc %}
)
{% doc %}Required for: snippets (always), blocks (when statically rendered via )
{% content_for 'block' %}liquid
{% doc %}
Brief description of what this file renders.
@param {type} name - Description of required parameter
@param {type} [name] - Description of optional parameter (brackets = optional)
@example
{% render 'snippet-name', name: value %}
{% enddoc %}Param types: , , , , ,
stringnumberbooleanimageobjectarray必填场景: snippets(始终需要)、blocks(当通过静态渲染时)
{% content_for 'block' %}liquid
{% doc %}
该文件渲染内容的简要说明。
@param {type} name - 必填参数说明
@param {type} [name] - 可选参数说明(方括号表示可选)
@example
{% render 'snippet-name', name: value %}
{% enddoc %}参数类型: , , , , ,
stringnumberbooleanimageobjectarrayTranslations
翻译
Every user-facing string must use the t
filter
t所有面向用户的字符串必须使用t
过滤器
tliquid
<!-- Correct -->
<h2>{{ 'sections.hero.heading' | t }}</h2>
<button>{{ 'products.add_to_cart' | t }}</button>
<!-- Wrong — never hardcode strings -->
<h2>Welcome to our store</h2>liquid
<!-- 正确写法 -->
<h2>{{ 'sections.hero.heading' | t }}</h2>
<button>{{ 'products.add_to_cart' | t }}</button>
<!-- 错误写法 — 禁止硬编码字符串 -->
<h2>欢迎光临我们的店铺</h2>Variable interpolation
变量插值
liquid
{{ 'products.price_range' | t: min: product.price_min | money, max: product.price_max | money }}Locale file:
json
{
"products": {
"price_range": "From {{ min }} to {{ max }}"
}
}liquid
{{ 'products.price_range' | t: min: product.price_min | money, max: product.price_max | money }}本地化文件:
json
{
"products": {
"price_range": "从 {{ min }} 到 {{ max }}"
}
}Locale file structure
本地化文件结构
locales/
├── en.default.json # English translations (required)
├── en.default.schema.json # Editor setting translations (required)
├── fr.json # French translations
└── fr.schema.json # French editor translationslocales/
├── en.default.json # 英文翻译(必填)
├── en.default.schema.json # 编辑器设置英文翻译(必填)
├── fr.json # 法文翻译
└── fr.schema.json # 编辑器设置法文翻译Key naming conventions
键命名规范
- Use snake_case and hierarchical keys (max 3 levels)
- Use sentence case for all text (capitalize first word only)
- Schema labels use prefix:
t:"label": "t:labels.heading" - Group by component: ,
sections.hero.headingblocks.slide.title
- 使用蛇形命名法和层级键(最多3级)
- 所有文本使用句首大写(仅首单词大写)
- Schema标签使用前缀:
t:"label": "t:labels.heading" - 按组件分组:,
sections.hero.headingblocks.slide.title
References
参考资料
- Filters: language (77), HTML/media (45), commerce (30)
- Tag reference (30 tags)
- Objects: commerce (5), content (10), tier 2 (69), tier 3 (53)
- Schema & settings reference (33 types)
- Complete examples (snippet, block, section)
- 过滤器:语言过滤器(77个)、HTML/媒体过滤器(45个)、电商过滤器(30个)
- 标签参考(30个标签)
- 对象:电商对象(5个)、内容对象(10个)、二级对象(69个)、三级对象(53个)
- Schema & 设置参考(33种类型)
- 完整示例(snippet、block、section)