shopify-liquid-themes

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Shopify 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

适用场景对比

NeedUseWhy
Full-width customizable moduleSectionHas
{% schema %}
, appears in editor, renders blocks
Small nestable component with editor settingsBlockHas
{% schema %}
, can nest inside sections/blocks
Reusable logic, not editable by merchantSnippetNo schema, rendered via
{% render %}
, takes params
Logic shared across blocks/snippetsSnippetBlocks can't
{% render %}
other blocks
需求使用对象原因
全宽可自定义模块Section包含
{% schema %}
, 可在编辑器中显示,支持渲染blocks
带编辑器设置的小型可嵌套组件Block包含
{% schema %}
, 可嵌套在sections/blocks中
不可被商家编辑的可复用逻辑Snippet无schema,通过
{% render %}
调用,支持传递参数
blocks/snippets间共享的逻辑Snippetblocks无法通过
{% render %}
调用其他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:
and
,
or
,
contains
比较运算符:
==
,
!=
,
>
,
<
,
>=
,
<=
逻辑运算符:
and
,
or
,
contains

Critical Gotchas

关键注意事项

  1. No parentheses in conditions — use nested
    {% if %}
    instead
  2. No ternary — always use
    {% if cond %}value{% else %}other{% endif %}
  3. for
    loops max 50 iterations
    — use
    {% paginate %}
    for larger arrays
  4. contains
    only works with strings
    — can't check objects in arrays
  5. {% stylesheet %}
    /
    {% javascript %}
    don't render Liquid
    — no Liquid inside them
  6. Snippets can't access outer-scope variables — pass them as render params
  7. include
    is deprecated
    — always use
    {% render 'snippet_name' %}
  8. {% liquid %}
    tag
    — multi-line logic without delimiters; use
    echo
    for output
  1. 条件判断中不支持括号 — 改用嵌套
    {% if %}
  2. 不支持三元表达式 — 始终使用
    {% if cond %}value{% else %}other{% endif %}
  3. for
    循环最多迭代50次 — 处理大型数组时使用
    {% paginate %}
  4. contains
    仅适用于字符串 — 无法检查数组中的对象
  5. {% stylesheet %}
    /
    {% javascript %}
    标签不解析Liquid — 标签内部不能写Liquid代码
  6. Snippets无法访问外部作用域变量 — 需通过render参数传递
  7. include
    已被弃用 — 始终使用
    {% render 'snippet_name' %}
  8. {% 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:
compact
,
concat
,
find
,
find_index
,
first
,
has
,
join
,
last
,
map
,
reject
,
reverse
,
size
,
sort
,
sort_natural
,
sum
,
uniq
,
where
String:
append
,
capitalize
,
downcase
,
escape
,
handleize
,
lstrip
,
newline_to_br
,
prepend
,
remove
,
replace
,
rstrip
,
slice
,
split
,
strip
,
strip_html
,
truncate
,
truncatewords
,
upcase
,
url_decode
,
url_encode
Math:
abs
,
at_least
,
at_most
,
ceil
,
divided_by
,
floor
,
minus
,
modulo
,
plus
,
round
,
times
Money:
money
,
money_with_currency
,
money_without_currency
,
money_without_trailing_zeros
Color:
color_brightness
,
color_darken
,
color_lighten
,
color_mix
,
color_modify
,
color_saturate
,
color_desaturate
,
color_to_hex
,
color_to_hsl
,
color_to_rgb
Media:
image_url
,
image_tag
,
video_tag
,
external_video_tag
,
media_tag
,
model_viewer_tag
URL:
asset_url
,
asset_img_url
,
file_url
,
shopify_asset_url
HTML:
link_to
,
script_tag
,
stylesheet_tag
,
time_tag
,
placeholder_svg_tag
Localization:
t
(translate),
format_address
,
currency_selector
Other:
date
,
default
,
json
,
structured_data
,
font_face
,
font_url
,
payment_button
Full details: language filters, HTML/media filters, commerce filters
过滤器通过
|
链式调用,前一个过滤器的输出作为后一个的输入。
数组类:
compact
,
concat
,
find
,
find_index
,
first
,
has
,
join
,
last
,
map
,
reject
,
reverse
,
size
,
sort
,
sort_natural
,
sum
,
uniq
,
where
字符串类:
append
,
capitalize
,
downcase
,
escape
,
handleize
,
lstrip
,
newline_to_br
,
prepend
,
remove
,
replace
,
rstrip
,
slice
,
split
,
strip
,
strip_html
,
truncate
,
truncatewords
,
upcase
,
url_decode
,
url_encode
数学类:
abs
,
at_least
,
at_most
,
ceil
,
divided_by
,
floor
,
minus
,
modulo
,
plus
,
round
,
times
金额类:
money
,
money_with_currency
,
money_without_currency
,
money_without_trailing_zeros
颜色类:
color_brightness
,
color_darken
,
color_lighten
,
color_mix
,
color_modify
,
color_saturate
,
color_desaturate
,
color_to_hex
,
color_to_hsl
,
color_to_rgb
媒体类:
image_url
,
image_tag
,
video_tag
,
external_video_tag
,
media_tag
,
model_viewer_tag
URL类:
asset_url
,
asset_img_url
,
file_url
,
shopify_asset_url
HTML类:
link_to
,
script_tag
,
stylesheet_tag
,
time_tag
,
placeholder_svg_tag
本地化类:
t
(翻译),
format_address
,
currency_selector
其他类:
date
,
default
,
json
,
structured_data
,
font_face
,
font_url
,
payment_button
详细说明:语言过滤器HTML/媒体过滤器电商过滤器

Tags Quick Reference

标签速查

CategoryTags
Theme
content_for
,
layout
,
section
,
sections
,
schema
,
stylesheet
,
javascript
,
style
Control
if
,
elsif
,
else
,
unless
,
case
,
when
Iteration
for
,
break
,
continue
,
cycle
,
tablerow
,
paginate
Variable
assign
,
capture
,
increment
,
decrement
,
echo
HTML
form
,
render
,
raw
,
comment
,
liquid
Documentation
doc
Full details with syntax and parameters: references/tags.md
分类标签
主题相关
content_for
,
layout
,
section
,
sections
,
schema
,
stylesheet
,
javascript
,
style
控制流
if
,
elsif
,
else
,
unless
,
case
,
when
循环迭代
for
,
break
,
continue
,
cycle
,
tablerow
,
paginate
变量操作
assign
,
capture
,
increment
,
decrement
,
echo
HTML相关
form
,
render
,
raw
,
comment
,
liquid
文档注释
doc
包含语法和参数的完整说明:references/tags.md

Objects Quick Reference

对象速查

Global objects (available everywhere)

全局对象(所有位置均可访问)

cart
,
collections
,
customer
,
localization
,
pages
,
request
,
routes
,
settings
,
shop
,
template
,
theme
,
linklists
,
images
,
blogs
,
articles
,
all_products
,
metaobjects
,
canonical_url
,
content_for_header
,
content_for_layout
,
page_title
,
page_description
,
handle
,
current_page
cart
,
collections
,
customer
,
localization
,
pages
,
request
,
routes
,
settings
,
shop
,
template
,
theme
,
linklists
,
images
,
blogs
,
articles
,
all_products
,
metaobjects
,
canonical_url
,
content_for_header
,
content_for_layout
,
page_title
,
page_description
,
handle
,
current_page

Page-specific objects

页面专属对象

TemplateObjects
/product
product
,
remote_product
/collection
collection
,
current_tags
/cart
cart
/article
article
,
blog
/blog
blog
,
current_tags
/page
page
/search
search
/customers/*
customer
,
order
Full reference: commerce objects, content objects, tier 2, tier 3
模板对象
/product
product
,
remote_product
/collection
collection
,
current_tags
/cart
cart
/article
article
,
blog
/blog
blog
,
current_tags
/page
page
/search
search
/customers/*
customer
,
order
完整参考:电商对象内容对象二级对象三级对象

Schema Tag

Schema 标签

Sections and blocks require
{% schema %}
with a valid JSON object. Sections use
section.settings.*
, blocks use
block.settings.*
.
Sections和blocks必须包含
{% schema %}
标签及有效的JSON对象。Sections使用
section.settings.*
,blocks使用
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

设置类型决策表

NeedSetting TypeKey Fields
On/off toggle
checkbox
default: true/false
Short text
text
placeholder
Long text
textarea
placeholder
Rich text (with
<p>
)
richtext
Inline rich text (no
<p>
)
inline_richtext
Number input
number
placeholder
Slider
range
min
,
max
,
default
(all required),
step
,
unit
Dropdown/segmented
select
options: [{value, label}]
Radio buttons
radio
options: [{value, label}]
Text alignment
text_alignment
default: "left"/"center"/"right"
Color picker
color
default: "#000000"
Image upload
image_picker
Video upload
video
External video URL
video_url
accept: ["youtube", "vimeo"]
Product picker
product
Collection picker
collection
Page picker
page
Blog picker
blog
Article picker
article
URL entry
url
Menu picker
link_list
Font picker
font_picker
default
(required)
Editor header
header
content
(no
id
needed)
Editor description
paragraph
content
(no
id
needed)
需求设置类型关键字段
开关按钮
checkbox
default: true/false
短文本输入
text
placeholder
长文本输入
textarea
placeholder
富文本(带
<p>
richtext
行内富文本(无
<p>
inline_richtext
数字输入
number
placeholder
滑块
range
min
,
max
,
default
(均为必填),
step
,
unit
下拉选择/分段选择
select
options: [{value, label}]
单选按钮
radio
options: [{value, label}]
文本对齐
text_alignment
default: "left"/"center"/"right"
颜色选择器
color
default: "#000000"
图片上传
image_picker
视频上传
video
外部视频URL
video_url
accept: ["youtube", "vimeo"]
产品选择器
product
集合选择器
collection
页面选择器
page
博客选择器
blog
文章选择器
article
URL输入
url
菜单选择器
link_list
字体选择器
font_picker
default
(必填)
编辑器标题
header
content
(无需
id
编辑器描述
paragraph
content
(无需
id

visible_if
pattern

visible_if
模式

json
{
  "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 条目类型

  • { "type": "@theme" }
    — Accept any theme block
  • { "type": "@app" }
    — Accept app blocks
  • { "type": "slide" }
    — Accept only the
    slide
    block type
Full schema details and all 33 setting types: references/schema-and-settings.md
  • { "type": "@theme" }
    — 支持任意主题block
  • { "type": "@app" }
    — 支持应用block
  • { "type": "slide" }
    — 仅支持
    slide
    类型的block
完整schema说明及全部33种设置类型:references/schema-and-settings.md

CSS & JavaScript

CSS & JavaScript

Per-component styles and scripts

组件专属样式与脚本

Use
{% stylesheet %}
and
{% javascript %}
in sections, blocks, and snippets:
liquid
{% stylesheet %}
  .my-component { display: flex; }
{% endstylesheet %}

{% javascript %}
  console.log('loaded');
{% endjavascript %}
  • One tag each per file — multiple
    {% stylesheet %}
    tags will error
  • No Liquid inside — these tags don't process Liquid; use CSS variables or classes instead
  • Only supported in
    sections/
    ,
    blocks/
    , and
    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 %}
标签(支持Liquid的CSS)

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

LiquidDoc(
{% 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:
string
,
number
,
boolean
,
image
,
object
,
array
必填场景: snippets(始终需要)、blocks(当通过
{% content_for 'block' %}
静态渲染时)
liquid
{% doc %}
  该文件渲染内容的简要说明。

  @param {type} name - 必填参数说明
  @param {type} [name] - 可选参数说明(方括号表示可选)

  @example
  {% render 'snippet-name', name: value %}
{% enddoc %}
参数类型:
string
,
number
,
boolean
,
image
,
object
,
array

Translations

翻译

Every user-facing string must use the
t
filter

所有面向用户的字符串必须使用
t
过滤器

liquid
<!-- 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 translations
locales/
├── 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
    t:
    prefix:
    "label": "t:labels.heading"
  • Group by component:
    sections.hero.heading
    ,
    blocks.slide.title
  • 使用蛇形命名法层级键(最多3级)
  • 所有文本使用句首大写(仅首单词大写)
  • Schema标签使用
    t:
    前缀:
    "label": "t:labels.heading"
  • 按组件分组:
    sections.hero.heading
    ,
    blocks.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)