shopify-liquid
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRequired Tool Calls (do not skip)
必需的工具调用(请勿跳过)
You have a tool. Every response must use it — in this order:
bash- Call with
bash— search before writing code Search limit: max 2 searches. If both returnnode scripts/search_docs.mjs "<tag, filter, or object name>", skip to step 2 using your built-in Liquid knowledge.[] - Write the code using the search results (or built-in knowledge if search returned nothing)
- Call with
bash— validate before returning (Always include these flags. Use your actual model name for YOUR_MODEL_NAME; use claude-code/cursor/etc. for YOUR_CLIENT_NAME. For YOUR_ARTIFACT_ID, generate a stable random ID per code block and reuse it across validation retries. For REVISION_NUMBER, start at 1 and increment on each retry of the same artifact.)node scripts/validate.mjs --filename <file.liquid> --filetype <sections|snippets|blocks|...> --code '<content>' --model YOUR_MODEL_NAME --client-name YOUR_CLIENT_NAME --client-version YOUR_CLIENT_VERSION --artifact-id YOUR_ARTIFACT_ID --revision REVISION_NUMBER - If validation fails: search for the error type, fix, re-validate (max 3 retries)
- Return code only after validation passes
You must run both search_docs.mjs and validate.mjs in every response. Do not return code to the user without completing step 3.
你有一个工具。每次响应都必须按以下顺序使用它:
bash- 执行运行
bash—— 编写代码前先搜索 搜索限制:最多2次搜索。如果两次都返回node scripts/search_docs.mjs "<标签、过滤器或对象名称>",请跳过此步骤,使用你内置的Liquid知识进入第2步。[] - 使用搜索结果编写代码(如果搜索无结果则使用内置知识)
- 执行运行
bash—— 返回代码前先校验 (始终包含这些参数。将YOUR_MODEL_NAME替换为你的实际模型名称;YOUR_CLIENT_NAME使用claude-code/cursor等。对于YOUR_ARTIFACT_ID,请为每个代码块生成一个稳定的随机ID,并在校验重试时复用该ID。对于REVISION_NUMBER,从1开始,同一工件每次重试时递增。)node scripts/validate.mjs --filename <file.liquid> --filetype <sections|snippets|blocks|...> --code '<content>' --model YOUR_MODEL_NAME --client-name YOUR_CLIENT_NAME --client-version YOUR_CLIENT_VERSION --artifact-id YOUR_ARTIFACT_ID --revision REVISION_NUMBER - 如果校验失败:搜索错误类型,修复后重新校验(最多重试3次)
- 仅在校验通过后返回代码
每次响应中你必须同时运行search_docs.mjs和validate.mjs。未完成第3步时不得向用户返回代码。
Your task
你的任务
You are an experienced Shopify theme developer, implement user requests by generating theme components that are consistent with the 'Key principles' and the 'Theme architecture'.
你是一名经验丰富的Shopify主题开发者,需要通过生成符合「核心原则」和「主题架构」的主题组件来实现用户需求。
Theme Architecture
主题架构
Key principles: focus on generating snippets, blocks, and sections; users may create templates using the theme editor
核心原则:重点生成snippets、blocks和sections;用户可以通过主题编辑器创建模板
Directory structure
目录结构
.
├── assets # Stores static assets (CSS, JS, images, fonts, etc.)
├── blocks # Reusable, nestable, customizable components
├── config # Global theme settings and customization options
├── layout # Top-level wrappers for pages (layout templates)
├── locales # Translation files for theme internationalization
├── sections # Modular full-width page components
├── snippets # Reusable Liquid code or HTML fragments
└── templates # Templates combining sections and blocks to define page structures.
├── assets # 存储静态资源(CSS、JS、图片、字体等)
├── blocks # 可复用、可嵌套、可自定义的组件
├── config # 全局主题设置和自定义选项
├── layout # 页面的顶层包装器(布局模板)
├── locales # 主题国际化的翻译文件
├── sections # 模块化的全宽页面组件
├── snippets # 可复用的Liquid代码或HTML片段
└── templates # 组合sections和blocks定义页面结构的模板sections
sectionssections
sections- Sections are files that allow you to create reusable modules that can be customized by merchants
.liquid - Sections can include blocks which allow merchants to add, remove, and reorder content within a section
- Sections are made customizable by including the required tag that exposes settings in the theme editor via a JSON object. Validate that JSON object using the
{% schema %}JSON schemaschemas/section.json - Examples of sections: hero banners, product grids, testimonials, featured collections
- Sections是文件,可用于创建商家可自定义的可复用模块
.liquid - Sections可包含blocks,允许商家在section内添加、删除和重新排序内容
- Sections通过包含必需的标签实现自定义,该标签通过JSON对象在主题编辑器中暴露设置。请使用
{% schema %}JSON schema校验该JSON对象schemas/section.json - Sections示例:首屏横幅、商品网格、用户评价、精选合集
blocks
blocksblocks
blocks- Blocks are files that allow you to create reusable small components that can be customized by merchants (they don't need to fit the full-width of the page)
.liquid - Blocks are ideal for logic that needs to be reused and also edited in the theme editor by merchants
- Blocks can include other nested blocks which allow merchants to add, remove, and reorder content within a block too
- Blocks are made customizable by including the required tag that exposes settings in the theme editor via a JSON object. Validate that JSON object using the
{% schema %}JSON schemaschemas/theme_block.json - Blocks must have the tag as the header if you directly/staticly render them in other file via
{% doc %}{% content_for 'block', id: '42', type: 'block_name' %} - Examples of blocks: individual testimonials, slides in a carousel, feature items
- Blocks是文件,可用于创建商家可自定义的小型可复用组件(不需要占满页面全宽)
.liquid - Blocks非常适合需要复用且允许商家在主题编辑器中编辑的逻辑
- Blocks可包含其他嵌套的block,允许商家在block内添加、删除和重新排序内容
- Blocks通过包含必需的标签实现自定义,该标签通过JSON对象在主题编辑器中暴露设置。请使用
{% schema %}JSON schema校验该JSON对象schemas/theme_block.json - 如果你通过在其他文件中直接/静态渲染blocks,则blocks必须以
{% content_for 'block', id: '42', type: 'block_name' %}标签作为头部{% doc %} - Blocks示例:单个用户评价、轮播图的单张幻灯片、功能项
snippets
snippetssnippets
snippets- Snippets are reusable code fragments rendered in blocks, sections, and layouts files via the tag
render - Snippets are ideal for logic that needs to be reused but not directly edited in the theme editor by merchants
- Snippets accept parameters when rendered for dynamic behavior
- Snippets must have the tag as the header
{% doc %} - Examples of sections: buttons, meta-tags, css-variables, and form elements
- Snippets是可复用的代码片段,可通过标签在blocks、sections和layout文件中渲染
render - Snippets非常适合需要复用但不需要商家在主题编辑器中直接编辑的逻辑
- Snippets在渲染时可接受参数以实现动态行为
- Snippets必须以标签作为头部
{% doc %} - Snippets示例:按钮、meta标签、css变量、表单元素
layout
layoutlayout
layout- Defines the overall HTML structure of the site, including and
<head>, and wraps other templates to provide a consistent frame<body> - Contains repeated global elements like navigation, cart drawer, footer, and usually includes CSS/JS assets and meta tags
- Must include to inject Shopify scripts in the
{{ content_for_header }}and<head>to render the page content{{ content_for_layout }}
- 定义站点的整体HTML结构,包括和
<head>,并包装其他模板以提供一致的框架<body> - 包含重复的全局元素,如导航、购物车抽屉、页脚,通常还包含CSS/JS资源和meta标签
- 必须包含以在
{{ content_for_header }}中注入Shopify脚本,以及<head>以渲染页面内容{{ content_for_layout }}
config
configconfig
config- is a JSON file that defines schema for global theme settings. Validate the shape shape of this JSON file using the
config/settings_schema.jsonJSON schemaschemas/theme_settings.json - is JSON file that holds the data for the settings defined by
config/settings_data.jsonconfig/settings_schema.json
- 是定义全局主题设置schema的JSON文件。请使用
config/settings_schema.jsonJSON schema校验该JSON文件的结构schemas/theme_settings.json - 是存储
config/settings_data.json定义的设置对应数据的JSON文件config/settings_schema.json
assets
assetsassets
assets- Contains static files like CSS, JavaScript, and images—including compiled and optimized assets—referenced in templates via the filter
asset_url - Keep it here only and static files necessary for every page, otherwise prefer the usage of the
critical.cssand{% stylesheet %}tags{% javascript %}
- 包含静态文件,如CSS、JavaScript和图片(包括编译和优化后的资源),可通过过滤器在模板中引用
asset_url - 仅在此处存放和每个页面都必需的静态文件,其他情况优先使用
critical.css和{% stylesheet %}标签{% javascript %}
locales
localeslocales
locales- Stores translation files organized by language code (e.g., ,
en.default.json) to localize all user-facing theme content and editor stringsfr.json - Enables multi-language support by providing translations accessible via filters like in Liquid for proper internationalization
{{ 'key' | t }} - Validate JSON files using the
localesJSON schemaschemas/translations.json
- 存储按语言代码组织的翻译文件(如、
en.default.json),用于本地化所有面向用户的主题内容和编辑器字符串fr.json - 通过Liquid中等过滤器可访问翻译内容,实现多语言支持,完成 proper 国际化
{{ 'key' | t }} - 请使用JSON schema校验
schemas/translations.jsonJSON文件locales
templates
templatestemplates
templates- JSON file that define the structure, ordering, and which sections and blocks appear on each page type, allowing merchants to customize layouts without code changes
- JSON文件,定义每个页面类型的结构、排序以及显示的sections和blocks,允许商家无需修改代码即可自定义布局
CSS & JavaScript
CSS & JavaScript
- Write CSS and JavaScript per components using the and
{% stylesheet %}tags{% javascript %} - Note: and
{% stylesheet %}are only supported in{% javascript %},snippets/, andblocks/sections/
- 使用和
{% stylesheet %}标签为每个组件编写CSS和JavaScript{% javascript %} - 注意:和
{% stylesheet %}仅在{% javascript %}、snippets/和blocks/中支持sections/
LiquidDoc
LiquidDoc
Snippets and blocks (when blocks are statically rendered) must include the LiquidDoc header that documents the purpose of the file and required parameters. Example:
liquid
{% doc %}
Renders a responsive image that might be wrapped in a link.
@param {image} image - The image to be rendered
@param {string} [url] - An optional destination URL for the image
@example
{% render 'image', image: product.featured_image %}
{% enddoc %}
<a href="{{ url | default: '#' }}">{{ image | image_url: width: 200, height: 200 | image_tag }}</a>Snippets和blocks(静态渲染时)必须包含LiquidDoc头部,用于记录文件的用途和所需参数。示例:
liquid
{% doc %}
Renders a responsive image that might be wrapped in a link.
@param {image} image - The image to be rendered
@param {string} [url] - An optional destination URL for the image
@example
{% render 'image', image: product.featured_image %}
{% enddoc %}
<a href="{{ url | default: '#' }}">{{ image | image_url: width: 200, height: 200 | image_tag }}</a>The {% schema %}
tag on blocks and sections
{% schema %}blocks和sections上的{% schema %}
标签
{% schema %}Key principles: follow the "Good practices" and "Validate the content" using JSON schemas
{% schema %}核心原则:遵循「最佳实践」,并使用JSON schema校验内容
{% schema %}Good practices
最佳实践
When defining the tag on sections and blocks, follow these guidelines to use the values:
{% schema %}Single property settings: For settings that correspond to a single CSS property, use CSS variables:
liquid
<div class="collection" style="--gap: {{ block.settings.gap }}px">
Example
</div>
{% stylesheet %}
.collection {
gap: var(--gap);
}
{% endstylesheet %}
{% schema %}
{
"settings": [{
"type": "range",
"label": "gap",
"id": "gap",
"min": 0,
"max": 100,
"unit": "px",
"default": 0,
}]
}
{% endschema %}Multiple property settings: For settings that control multiple CSS properties, use CSS classes:
liquid
<div class="collection {{ block.settings.layout }}">
Example
</div>
{% stylesheet %}
.collection--full-width {
/* multiple styles */
}
.collection--narrow {
/* multiple styles */
}
{% endstylesheet %}
{% schema %}
{
"settings": [{
"type": "select",
"id": "layout",
"label": "layout",
"values": [
{ "value": "collection--full-width", "label": "t:options.full" },
{ "value": "collection--narrow", "label": "t:options.narrow" }
]
}]
}
{% endschema %}在sections和blocks上定义标签时,遵循以下指南使用设置值:
{% schema %}单属性设置:对于对应单个CSS属性的设置,使用CSS变量:
liquid
<div class="collection" style="--gap: {{ block.settings.gap }}px">
示例
</div>
{% stylesheet %}
.collection {
gap: var(--gap);
}
{% endstylesheet %}
{% schema %}
{
"settings": [{
"type": "range",
"label": "gap",
"id": "gap",
"min": 0,
"max": 100,
"unit": "px",
"default": 0,
}]
}
{% endschema %}多属性设置:对于控制多个CSS属性的设置,使用CSS类:
liquid
<div class="collection {{ block.settings.layout }}">
示例
</div>
{% stylesheet %}
.collection--full-width {
/* 多个样式 */
}
.collection--narrow {
/* 多个样式 */
}
{% endstylesheet %}
{% schema %}
{
"settings": [{
"type": "select",
"id": "layout",
"label": "layout",
"values": [
{ "value": "collection--full-width", "label": "t:options.full" },
{ "value": "collection--narrow", "label": "t:options.narrow" }
]
}]
}
{% endschema %}Mobile layouts
移动端布局
If you need to create a mobile layout and you want the merchant to be able to select one or two columns, use a select input:
liquid
{% schema %}
{
"type": "select",
"id": "columns_mobile",
"label": "Columns on mobile",
"options": [
{ "value": 1, "label": "1" },
{ "value": "2", "label": "2" }
]
}
{% endschema %}如果你需要创建移动端布局,并且希望商家可以选择1列或2列,请使用select输入框:
liquid
{% schema %}
{
"type": "select",
"id": "columns_mobile",
"label": "移动端列数",
"options": [
{ "value": 1, "label": "1" },
{ "value": "2", "label": "2" }
]
}
{% endschema %}Liquid
Liquid
Liquid delimiters
Liquid分隔符
- : Output – prints a value.
{{ ... }} - : Output, trims whitespace around the value.
{{- ... -}} - : Logic/control tag (if, for, assign, etc.), does not print anything, no whitespace trim.
{% ... %} - : Logic/control tag, trims whitespace around the tag.
{%- ... -%}
Tip:
Adding a dash () after / or before / trims spaces or newlines next to the tag.
-{%{{%}}}Examples:
- → print value, remove surrounding spaces or lines.
{{- product.title -}} - → logic, removes extra spaces/lines.
{%- if available -%}In stock{%- endif -%}
- :输出 – 打印值
{{ ... }} - :输出,修剪值周围的空白
{{- ... -}} - :逻辑/控制标签(if、for、assign等),不打印任何内容,不修剪空白
{% ... %} - :逻辑/控制标签,修剪标签周围的空白
{%- ... -%}
提示:
在/后或/前添加短横线()会修剪标签旁边的空格或换行符。
{%{{%}}}-示例:
- → 打印值,移除周围的空格或换行
{{- product.title -}} - → 逻辑,移除多余的空格/换行
{%- if available -%}有货{%- endif -%}
Liquid operators
Liquid运算符
Comparison operators:
- ==
- !=
-
- <
-
=
- <=
Logical operators:
orand- - checks if a string contains a substring, or if an array contains a string
contains
比较运算符:
- ==
- !=
-
- <
-
=
- <=
逻辑运算符:
orand- – 检查字符串是否包含子字符串,或数组是否包含字符串
contains
Comparison and comparison tags
比较和比较标签
Key condition principles:
- For simplificity, ALWAYS use nested conditions when the logic requires more than one logical operator
if - Parentheses are not supported in Liquid
- Ternary conditionals are not supported in Liquid, so always use
{% if cond %}
Basic comparison example:
liquid
{% if product.title == "Awesome Shoes" %}
These shoes are awesome!
{% endif %}Multiple Conditions:
liquid
{% if product.type == "Shirt" or product.type == "Shoes" %}
This is a shirt or a pair of shoes.
{% endif %}Contains Usage:
- For strings:
{% if product.title contains "Pack" %} - For arrays:
{% if product.tags contains "Hello" %} - Note: only works with strings, not objects in arrays
contains
{% elsif %} (used inside if/unless only)
liquid
{% if a %}
...
{% elsif b %}
...
{% endif %}{% unless %}
liquid
{% unless condition %}
...
{% endunless %}{% case %}
liquid
{% case variable %}
{% when 'a' %}
a
{% when 'b' %}
b
{% else %}
other
{% endcase %}{% else %} (used inside if, unless, case, or for)
liquid
{% if product.available %}
In stock
{% else %}
Sold out
{% endif %}or inside a for loop:
liquid
{% for item in collection.products %}
{{ item.title }}
{% else %}
No products found.
{% endfor %}核心条件原则:
- 为简化逻辑,当逻辑需要多个逻辑运算符时,始终使用嵌套的条件
if - Liquid不支持括号
- Liquid不支持三元条件,因此始终使用
{% if cond %}
基础比较示例:
liquid
{% if product.title == "Awesome Shoes" %}
这双鞋太棒了!
{% endif %}多条件:
liquid
{% if product.type == "Shirt" or product.type == "Shoes" %}
这是一件衬衫或一双鞋。
{% endif %}contains用法:
- 字符串用法:
{% if product.title contains "Pack" %} - 数组用法:
{% if product.tags contains "Hello" %} - 注意:仅适用于字符串,不适用于数组中的对象
contains
{% elsif %}(仅在if/unless内部使用)
liquid
{% if a %}
...
{% elsif b %}
...
{% endif %}{% unless %}
liquid
{% unless condition %}
...
{% endunless %}{% case %}
liquid
{% case variable %}
{% when 'a' %}
a
{% when 'b' %}
b
{% else %}
其他
{% endcase %}{% else %}(在if、unless、case或for内部使用)
liquid
{% if product.available %}
有货
{% else %}
售罄
{% endif %}或在for循环内部使用:
liquid
{% for item in collection.products %}
{{ item.title }}
{% else %}
未找到商品。
{% endfor %}Variables and variable tags
变量和变量标签
liquid
{% assign my_variable = 'value' %}
{% capture my_variable %}
Contents of variable
{% endcapture %}
{% increment counter %}
{% decrement counter %}liquid
{% assign my_variable = 'value' %}
{% capture my_variable %}
变量内容
{% endcapture %}
{% increment counter %}
{% decrement counter %}Liquid filters
Liquid过滤器
You can chain filters in Liquid, passing the result of one filter as the input to the next.
See these filters:
- :
upcasereturns a string{{ string | upcase }} - :
splitreturns an array (as we may notice in the docs,{{ string | split: string }}receives a string as its argument)split - :
lastreturns untyped{{ array | last }}
Each filter can pass its return value to the next filter as long as the types match.
For example, returns a string, which is suitable input for , which then produces an array for to use.
upcasesplitlastHere's how the filters are executed step by step to eventually return :
"WORLD"liquid
{{ "hello world" | upcase | split: " " | last }}- First, is converted to uppercase:
"hello world", which is a string"HELLO WORLD" - Next, can act on strings, so it splits the value by space into an array:
split["HELLO", "WORLD"] - Finally, the filter work with array, so
lastis returned"WORLD"
你可以在Liquid中链式使用过滤器,将一个过滤器的结果作为下一个过滤器的输入。
参考这些过滤器:
- :
upcase返回 字符串{{ string | upcase }} - :
split返回 数组(正如文档中提到的,{{ string | split: string }}接收字符串作为参数)split - :
last返回 无类型{{ array | last }}
只要类型匹配,每个过滤器都可以将其返回值传递给下一个过滤器。
例如,返回字符串,适合作为的输入,生成数组供使用。
upcasesplitsplitlast以下是过滤器逐步执行最终返回的过程:
"WORLD"liquid
{{ "hello world" | upcase | split: " " | last }}- 首先,被转换为大写:
"hello world",是字符串"HELLO WORLD" - 接下来,作用于字符串,按空格将值拆分为数组:
split["HELLO", "WORLD"] - 最后,过滤器处理数组,返回
last"WORLD"
Array
数组
- :
compactreturns{{ array | compact }}array - :
concatreturns{{ array | concat: array }}array - :
findreturns{{ array | find: string, string }}untyped - :
find_indexreturns{{ array | find_index: string, string }}number - :
firstreturns{{ array | first }}untyped - :
hasreturns{{ array | has: string, string }}boolean - :
joinreturns{{ array | join }}string - :
lastreturns{{ array | last }}untyped - :
mapreturns{{ array | map: string }}array - :
rejectreturns{{ array | reject: string, string }}array - :
reversereturns{{ array | reverse }}array - :
sizereturns{{ variable | size }}number - :
sortreturns{{ array | sort }}array - :
sort_naturalreturns{{ array | sort_natural }}array - :
sumreturns{{ array | sum }}number - :
uniqreturns{{ array | uniq }}array - :
wherereturns{{ array | where: string, string }}array
- :
compact返回{{ array | compact }}array - :
concat返回{{ array | concat: array }}array - :
find返回{{ array | find: string, string }}untyped - :
find_index返回{{ array | find_index: string, string }}number - :
first返回{{ array | first }}untyped - :
has返回{{ array | has: string, string }}boolean - :
join返回{{ array | join }}string - :
last返回{{ array | last }}untyped - :
map返回{{ array | map: string }}array - :
reject返回{{ array | reject: string, string }}array - :
reverse返回{{ array | reverse }}array - :
size返回{{ variable | size }}number - :
sort返回{{ array | sort }}array - :
sort_natural返回{{ array | sort_natural }}array - :
sum返回{{ array | sum }}number - :
uniq返回{{ array | uniq }}array - :
where返回{{ array | where: string, string }}array
Cart
购物车
- :
item_count_for_variantreturns{{ cart | item_count_for_variant: {variant_id} }}number - :
line_items_forreturns{{ cart | line_items_for: object }}array
- :
item_count_for_variant返回{{ cart | item_count_for_variant: {variant_id} }}number - :
line_items_for返回{{ cart | line_items_for: object }}array
Collection
合集
- :
link_to_typereturns{{ string | link_to_type }}string - :
link_to_vendorreturns{{ string | link_to_vendor }}string - :
sort_byreturns{{ string | sort_by: string }}string - :
url_for_typereturns{{ string | url_for_type }}string - :
url_for_vendorreturns{{ string | url_for_vendor }}string - :
withinreturns{{ string | within: collection }}string - :
highlight_active_tagreturns{{ string | highlight_active_tag }}string
- :
link_to_type返回{{ string | link_to_type }}string - :
link_to_vendor返回{{ string | link_to_vendor }}string - :
sort_by返回{{ string | sort_by: string }}string - :
url_for_type返回{{ string | url_for_type }}string - :
url_for_vendor返回{{ string | url_for_vendor }}string - :
within返回{{ string | within: collection }}string - :
highlight_active_tag返回{{ string | highlight_active_tag }}string
Color
颜色
- :
brightness_differencereturns{{ string | brightness_difference: string }}number - :
color_brightnessreturns{{ string | color_brightness }}number - :
color_contrastreturns{{ string | color_contrast: string }}number - :
color_darkenreturns{{ string | color_darken: number }}string - :
color_desaturatereturns{{ string | color_desaturate: number }}string - :
color_differencereturns{{ string | color_difference: string }}number - :
color_extractreturns{{ string | color_extract: string }}number - :
color_lightenreturns{{ string | color_lighten: number }}string - :
color_mixreturns{{ string | color_mix: string, number }}string - :
color_modifyreturns{{ string | color_modify: string, number }}string - :
color_saturatereturns{{ string | color_saturate: number }}string - :
color_to_hexreturns{{ string | color_to_hex }}string - :
color_to_hslreturns{{ string | color_to_hsl }}string - :
color_to_oklchreturns{{ string | color_to_oklch }}string - :
color_to_rgbreturns{{ string | color_to_rgb }}string - :
hex_to_rgbareturns{{ string | hex_to_rgba }}string
- :
brightness_difference返回{{ string | brightness_difference: string }}number - :
color_brightness返回{{ string | color_brightness }}number - :
color_contrast返回{{ string | color_contrast: string }}number - :
color_darken返回{{ string | color_darken: number }}string - :
color_desaturate返回{{ string | color_desaturate: number }}string - :
color_difference返回{{ string | color_difference: string }}number - :
color_extract返回{{ string | color_extract: string }}number - :
color_lighten返回{{ string | color_lighten: number }}string - :
color_mix返回{{ string | color_mix: string, number }}string - :
color_modify返回{{ string | color_modify: string, number }}string - :
color_saturate返回{{ string | color_saturate: number }}string - :
color_to_hex返回{{ string | color_to_hex }}string - :
color_to_hsl返回{{ string | color_to_hsl }}string - :
color_to_oklch返回{{ string | color_to_oklch }}string - :
color_to_rgb返回{{ string | color_to_rgb }}string - :
hex_to_rgba返回{{ string | hex_to_rgba }}string
Customer
客户
- :
customer_login_linkreturns{{ string | customer_login_link }}string - :
customer_logout_linkreturns{{ string | customer_logout_link }}string - :
customer_register_linkreturns{{ string | customer_register_link }}string - :
avatarreturns{{ customer | avatar }}string - :
login_buttonreturns{{ shop | login_button }}string
- :
customer_login_link返回{{ string | customer_login_link }}string - :
customer_logout_link返回{{ string | customer_logout_link }}string - :
customer_register_link返回{{ string | customer_register_link }}string - :
avatar返回{{ customer | avatar }}string - :
login_button返回{{ shop | login_button }}string
Date
日期
- :
datereturns{{ date | date: string }}string
- :
date返回{{ date | date: string }}string
Default
默认
- :
default_errorsreturns{{ string | default_errors }}string - :
defaultreturns{{ variable | default: variable }}untyped - :
default_paginationreturns{{ paginate | default_pagination }}string
- :
default_errors返回{{ string | default_errors }}string - :
default返回{{ variable | default: variable }}untyped - :
default_pagination返回{{ paginate | default_pagination }}string
Font
字体
- :
font_facereturns{{ font | font_face }}string - :
font_modifyreturns{{ font | font_modify: string, string }}font - :
font_urlreturns{{ font | font_url }}string
- :
font_face返回{{ font | font_face }}string - :
font_modify返回{{ font | font_modify: string, string }}font - :
font_url返回{{ font | font_url }}string
Format
格式
- :
datereturns{{ string | date: string }}string - :
jsonreturns{{ variable | json }}string - :
structured_datareturns{{ variable | structured_data }}string - :
unit_price_with_measurementreturns{{ number | unit_price_with_measurement: unit_price_measurement }}string - :
weight_with_unitreturns{{ number | weight_with_unit }}string
- :
date返回{{ string | date: string }}string - :
json返回{{ variable | json }}string - :
structured_data返回{{ variable | structured_data }}string - :
unit_price_with_measurement返回{{ number | unit_price_with_measurement: unit_price_measurement }}string - :
weight_with_unit返回{{ number | weight_with_unit }}string
Hosted_file
托管文件
- :
asset_img_urlreturns{{ string | asset_img_url }}string - :
asset_urlreturns{{ string | asset_url }}string - :
file_img_urlreturns{{ string | file_img_url }}string - :
file_urlreturns{{ string | file_url }}string - :
global_asset_urlreturns{{ string | global_asset_url }}string - :
shopify_asset_urlreturns{{ string | shopify_asset_url }}string
- :
asset_img_url返回{{ string | asset_img_url }}string - :
asset_url返回{{ string | asset_url }}string - :
file_img_url返回{{ string | file_img_url }}string - :
file_url返回{{ string | file_url }}string - :
global_asset_url返回{{ string | global_asset_url }}string - :
shopify_asset_url返回{{ string | shopify_asset_url }}string
Html
Html
- :
class_listreturns{{ settings.layout | class_list }}string - :
time_tagreturns{{ string | time_tag: string }}string - :
inline_asset_contentreturns{{ asset_name | inline_asset_content }}string - :
highlightreturns{{ string | highlight: string }}string - :
link_toreturns{{ string | link_to: string }}string - :
placeholder_svg_tagreturns{{ string | placeholder_svg_tag }}string - :
preload_tagreturns{{ string | preload_tag: as: string }}string - :
script_tagreturns{{ string | script_tag }}string - :
stylesheet_tagreturns{{ string | stylesheet_tag }}string
- :
class_list返回{{ settings.layout | class_list }}string - :
time_tag返回{{ string | time_tag: string }}string - :
inline_asset_content返回{{ asset_name | inline_asset_content }}string - :
highlight返回{{ string | highlight: string }}string - :
link_to返回{{ string | link_to: string }}string - :
placeholder_svg_tag返回{{ string | placeholder_svg_tag }}string - :
preload_tag返回{{ string | preload_tag: as: string }}string - :
script_tag返回{{ string | script_tag }}string - :
stylesheet_tag返回{{ string | stylesheet_tag }}string
Localization
本地化
- :
currency_selectorreturns{{ form | currency_selector }}string - :
translatereturns{{ string | t }}string - :
format_addressreturns{{ address | format_address }}string
- :
currency_selector返回{{ form | currency_selector }}string - :
translate返回{{ string | t }}string - :
format_address返回{{ address | format_address }}string
Math
数学
- :
absreturns{{ number | abs }}number - :
at_leastreturns{{ number | at_least }}number - :
at_mostreturns{{ number | at_most }}number - :
ceilreturns{{ number | ceil }}number - :
divided_byreturns{{ number | divided_by: number }}number - :
floorreturns{{ number | floor }}number - :
minusreturns{{ number | minus: number }}number - :
moduloreturns{{ number | modulo: number }}number - :
plusreturns{{ number | plus: number }}number - :
roundreturns{{ number | round }}number - :
timesreturns{{ number | times: number }}number
- :
abs返回{{ number | abs }}number - :
at_least返回{{ number | at_least }}number - :
at_most返回{{ number | at_most }}number - :
ceil返回{{ number | ceil }}number - :
divided_by返回{{ number | divided_by: number }}number - :
floor返回{{ number | floor }}number - :
minus返回{{ number | minus: number }}number - :
modulo返回{{ number | modulo: number }}number - :
plus返回{{ number | plus: number }}number - :
round返回{{ number | round }}number - :
times返回{{ number | times: number }}number
Media
媒体
- :
external_video_tagreturns{{ variable | external_video_tag }}string - :
external_video_urlreturns{{ media | external_video_url: attribute: string }}string - :
image_tagreturns{{ string | image_tag }}string - :
media_tagreturns{{ media | media_tag }}string - :
model_viewer_tagreturns{{ media | model_viewer_tag }}string - :
video_tagreturns{{ media | video_tag }}string - :
article_img_urlreturns{{ variable | article_img_url }}string - :
collection_img_urlreturns{{ variable | collection_img_url }}string - :
image_urlreturns{{ variable | image_url: width: number, height: number }}string - :
img_tagreturns{{ string | img_tag }}string - :
img_urlreturns{{ variable | img_url }}string - :
product_img_urlreturns{{ variable | product_img_url }}string
- :
external_video_tag返回{{ variable | external_video_tag }}string - :
external_video_url返回{{ media | external_video_url: attribute: string }}string - :
image_tag返回{{ string | image_tag }}string - :
media_tag返回{{ media | media_tag }}string - :
model_viewer_tag返回{{ media | model_viewer_tag }}string - :
video_tag返回{{ media | video_tag }}string - :
article_img_url返回{{ variable | article_img_url }}string - :
collection_img_url返回{{ variable | collection_img_url }}string - :
image_url返回{{ variable | image_url: width: number, height: number }}string - :
img_tag返回{{ string | img_tag }}string - :
img_url返回{{ variable | img_url }}string - :
product_img_url返回{{ variable | product_img_url }}string
Metafield
元字段
- :
metafield_tagreturns{{ metafield | metafield_tag }}string - :
metafield_textreturns{{ metafield | metafield_text }}string
- :
metafield_tag返回{{ metafield | metafield_tag }}string - :
metafield_text返回{{ metafield | metafield_text }}string
Money
金额
- :
moneyreturns{{ number | money }}string - :
money_with_currencyreturns{{ number | money_with_currency }}string - :
money_without_currencyreturns{{ number | money_without_currency }}string - :
money_without_trailing_zerosreturns{{ number | money_without_trailing_zeros }}string
- :
money返回{{ number | money }}string - :
money_with_currency返回{{ number | money_with_currency }}string - :
money_without_currency返回{{ number | money_without_currency }}string - :
money_without_trailing_zeros返回{{ number | money_without_trailing_zeros }}string
Payment
支付
- :
payment_buttonreturns{{ form | payment_button }}string - :
payment_termsreturns{{ form | payment_terms }}string - :
payment_type_img_urlreturns{{ string | payment_type_img_url }}string - :
payment_type_svg_tagreturns{{ string | payment_type_svg_tag }}string
- :
payment_button返回{{ form | payment_button }}string - :
payment_terms返回{{ form | payment_terms }}string - :
payment_type_img_url返回{{ string | payment_type_img_url }}string - :
payment_type_svg_tag返回{{ string | payment_type_svg_tag }}string
String
字符串
- :
hmac_sha1returns{{ string | hmac_sha1: string }}string - :
hmac_sha256returns{{ string | hmac_sha256: string }}string - :
md5returns{{ string | md5 }}string - :
sha1returns{{ string | sha1: string }}string - :
sha256returns{{ string | sha256: string }}string - :
appendreturns{{ string | append: string }}string - :
base64_decodereturns{{ string | base64_decode }}string - :
base64_encodereturns{{ string | base64_encode }}string - :
base64_url_safe_decodereturns{{ string | base64_url_safe_decode }}string - :
base64_url_safe_encodereturns{{ string | base64_url_safe_encode }}string - :
capitalizereturns{{ string | capitalize }}string - :
downcasereturns{{ string | downcase }}string - :
escapereturns{{ string | escape }}string - :
escape_oncereturns{{ string | escape_once }}string - :
lstripreturns{{ string | lstrip }}string - :
newline_to_brreturns{{ string | newline_to_br }}string - :
prependreturns{{ string | prepend: string }}string - :
removereturns{{ string | remove: string }}string - :
remove_firstreturns{{ string | remove_first: string }}string - :
remove_lastreturns{{ string | remove_last: string }}string - :
replacereturns{{ string | replace: string, string }}string - :
replace_firstreturns{{ string | replace_first: string, string }}string - :
replace_lastreturns{{ string | replace_last: string, string }}string - :
rstripreturns{{ string | rstrip }}string - :
slicereturns{{ string | slice }}string - :
splitreturns{{ string | split: string }}array - :
stripreturns{{ string | strip }}string - :
strip_htmlreturns{{ string | strip_html }}string - :
strip_newlinesreturns{{ string | strip_newlines }}string - :
truncatereturns{{ string | truncate: number }}string - :
truncatewordsreturns{{ string | truncatewords: number }}string - :
upcasereturns{{ string | upcase }}string - :
url_decodereturns{{ string | url_decode }}string - :
url_encodereturns{{ string | url_encode }}string - :
camelizereturns{{ string | camelize }}string - :
handleizereturns{{ string | handleize }}string - :
url_escapereturns{{ string | url_escape }}string - :
url_param_escapereturns{{ string | url_param_escape }}string - :
pluralizereturns{{ number | pluralize: string, string }}string
- :
hmac_sha1返回{{ string | hmac_sha1: string }}string - :
hmac_sha256返回{{ string | hmac_sha256: string }}string - :
md5返回{{ string | md5 }}string - :
sha1返回{{ string | sha1: string }}string - :
sha256返回{{ string | sha256: string }}string - :
append返回{{ string | append: string }}string - :
base64_decode返回{{ string | base64_decode }}string - :
base64_encode返回{{ string | base64_encode }}string - :
base64_url_safe_decode返回{{ string | base64_url_safe_decode }}string - :
base64_url_safe_encode返回{{ string | base64_url_safe_encode }}string - :
capitalize返回{{ string | capitalize }}string - :
downcase返回{{ string | downcase }}string - :
escape返回{{ string | escape }}string - :
escape_once返回{{ string | escape_once }}string - :
lstrip返回{{ string | lstrip }}string - :
newline_to_br返回{{ string | newline_to_br }}string - :
prepend返回{{ string | prepend: string }}string - :
remove返回{{ string | remove: string }}string - :
remove_first返回{{ string | remove_first: string }}string - :
remove_last返回{{ string | remove_last: string }}string - :
replace返回{{ string | replace: string, string }}string - :
replace_first返回{{ string | replace_first: string, string }}string - :
replace_last返回{{ string | replace_last: string, string }}string - :
rstrip返回{{ string | rstrip }}string - :
slice返回{{ string | slice }}string - :
split返回{{ string | split: string }}array - :
strip返回{{ string | strip }}string - :
strip_html返回{{ string | strip_html }}string - :
strip_newlines返回{{ string | strip_newlines }}string - :
truncate返回{{ string | truncate: number }}string - :
truncatewords返回{{ string | truncatewords: number }}string - :
upcase返回{{ string | upcase }}string - :
url_decode返回{{ string | url_decode }}string - :
url_encode返回{{ string | url_encode }}string - :
camelize返回{{ string | camelize }}string - :
handleize返回{{ string | handleize }}string - :
url_escape返回{{ string | url_escape }}string - :
url_param_escape返回{{ string | url_param_escape }}string - :
pluralize返回{{ number | pluralize: string, string }}string
Tag
标签
- :
link_to_add_tagreturns{{ string | link_to_add_tag }}string - :
link_to_remove_tagreturns{{ string | link_to_remove_tag }}string - :
link_to_tagreturns{{ string | link_to_tag }}string
- :
link_to_add_tag返回{{ string | link_to_add_tag }}string - :
link_to_remove_tag返回{{ string | link_to_remove_tag }}string - :
link_to_tag返回{{ string | link_to_tag }}string
Liquid objects
Liquid对象
Global objects
全局对象
collectionspagesall_productsarticlesblogscartclosestcontent_for_headercustomerimageslinklistslocalizationmetaobjectsrequestroutesshopthemesettingstemplateadditional_checkout_buttonsall_country_option_tagscanonical_urlcontent_for_additional_checkout_buttonscontent_for_indexcontent_for_layoutcountry_option_tagscurrent_pagehandlepage_descriptionpage_imagepage_titlepowered_by_linkscripts
collectionspagesall_productsarticlesblogscartclosestcontent_for_headercustomerimageslinklistslocalizationmetaobjectsrequestroutesshopthemesettingstemplateadditional_checkout_buttonsall_country_option_tagscanonical_urlcontent_for_additional_checkout_buttonscontent_for_indexcontent_for_layoutcountry_option_tagscurrent_pagehandlepage_descriptionpage_imagepage_titlepowered_by_linkscripts
/article
page
/article/article
页面
/articlearticleblog
articleblog
/blog
page
/blog/blog
页面
/blogblogcurrent_tags
blogcurrent_tags
/cart
page
/cart/cart
页面
/cartcart
cart
/checkout
page
/checkout/checkout
页面
/checkoutcheckout
checkout
/collection
page
/collection/collection
页面
/collectioncollectioncurrent_tags
collectioncurrent_tags
/customers/account
page
/customers/account/customers/account
页面
/customers/accountcustomer
customer
/customers/addresses
page
/customers/addresses/customers/addresses
页面
/customers/addressescustomer
customer
/customers/order
page
/customers/order/customers/order
页面
/customers/ordercustomerorder
customerorder
/gift_card.liquid
page
/gift_card.liquid/gift_card.liquid
页面
/gift_card.liquidgift_cardrecipient
gift_cardrecipient
/metaobject
page
/metaobject/metaobject
页面
/metaobjectmetaobject
metaobject
/page
page
/page/page
页面
/pagepage
page
/product
page
/product/product
页面
/productproduct
product
/robots.txt.liquid
page
/robots.txt.liquid/robots.txt.liquid
页面
/robots.txt.liquidrobots
robots
/search
page
/search/search
页面
/searchsearch
search
Liquid tags
Liquid标签
content_for
content_for
The tag requires a type parameter to differentiate between rendering a number of theme blocks () and a single static block ().
content_for'blocks''block'Syntax:
{% content_for 'blocks' %}
{% content_for 'block', type: "slide", id: "slide-1" %}content_for'blocks''block'语法:
{% content_for 'blocks' %}
{% content_for 'block', type: "slide", id: "slide-1" %}form
form
Because there are many different form types available in Shopify themes, the tag requires a type. Depending on the
form type, an additional parameter might be required. You can specify the following form types:
formactivate_customer_passwordcartcontactcreate_customercurrencycustomercustomer_addresscustomer_loginguest_loginlocalizationnew_commentproductrecover_customer_passwordreset_customer_passwordstorefront_password
Syntax:
{% form 'form_type' %}
content
{% endform %}由于Shopify主题中有多种不同的表单类型,标签需要指定type。根据表单类型的不同,可能需要额外的参数。你可以指定以下表单类型:
formactivate_customer_passwordcartcontactcreate_customercurrencycustomercustomer_addresscustomer_loginguest_loginlocalizationnew_commentproductrecover_customer_passwordreset_customer_passwordstorefront_password
语法:
{% form 'form_type' %}
content
{% endform %}layout
layout
Syntax:
{% layout name %}语法:
{% layout name %}assign
assign
You can create variables of any basic type, object, or object property.
Caution: Predefined Liquid objects can be overridden by variables with the same name. To make sure that you can access all Liquid objects, make sure that your variable name doesn't match a predefined object's name.
Syntax:
{% assign variable_name = value %}break
break
Syntax:
{% break %}语法:
{% break %}capture
capture
You can create complex strings with Liquid logic and variables.
Caution: Predefined Liquid objects can be overridden by variables with the same name. To make sure that you can access all Liquid objects, make sure that your variable name doesn't match a predefined object's name.
Syntax:
{% capture variable %}
value
{% endcapture %}你可以使用Liquid逻辑和变量创建复杂字符串。
注意: 预定义的Liquid对象可能会被同名变量覆盖。 为确保你可以访问所有Liquid对象,请确保你的变量名与预定义对象的名称不冲突。
语法:
{% capture variable %}
value
{% endcapture %}case
case
Syntax:
{% case variable %}
{% when first_value %}
first_expression
{% when second_value %}
second_expression
{% else %}
third_expression
{% endcase %}语法:
{% case variable %}
{% when first_value %}
first_expression
{% when second_value %}
second_expression
{% else %}
third_expression
{% endcase %}comment
comment
Any text inside tags won't be output, and any Liquid code will be parsed, but not executed.
commentSyntax:
{% comment %}
content
{% endcomment %}comment语法:
{% comment %}
content
{% endcomment %}continue
continue
Syntax:
{% continue %}语法:
{% continue %}cycle
cycle
The tag must be used inside a loop.
cycleforTip: Use thetag to output text in a predictable pattern. For example, to apply odd/even classes to rows in a table.cycle
Syntax:
{% cycle string, string, ... %}cyclefor提示: 使用标签可以按可预测的模式输出文本。例如,为表格的行应用奇/偶类。cycle
语法:
{% cycle string, string, ... %}decrement
decrement
Variables that are declared with are unique to the layout, template,
or section file that they're created in. However, the variable is shared across
snippets included in the file.
decrementSimilarly, variables that are created with are independent from those created with
and . However, and share
variables.
decrementassigncapturedecrementincrementSyntax:
{% decrement variable_name %}doc
doc
The tag allows developers to include documentation within Liquid
templates. Any content inside tags is not rendered or outputted.
Liquid code inside will be parsed but not executed. This facilitates
tooling support for features like code completion, linting, and inline
documentation.
docdocFor detailed documentation syntax and examples, see the
reference.
LiquidDocSyntax:
{% doc %}
Renders a message.
@param {string} foo - A string value.
@param {string} [bar] - An optional string value.
@example
{% render 'message', foo: 'Hello', bar: 'World' %}
{% enddoc %}docdoc有关详细的文档语法和示例,请参阅参考。
LiquidDoc语法:
{% doc %}
Renders a message.
@param {string} foo - A string value.
@param {string} [bar] - An optional string value.
@example
{% render 'message', foo: 'Hello', bar: 'World' %}
{% enddoc %}echo
echo
Using the tag is the same as wrapping an expression in curly brackets ( and ). However, unlike the curly
bracket method, you can use the tag inside tags.
echo{{}}echoliquidTip: You can use filters on expressions insidetags.echo
Syntax:
{% liquid
echo expression
%}for
for
You can do a maximum of 50 iterations with a loop. If you need to iterate over more than 50 items, then use the
tag to split the items over multiple pages.
forpaginateTip: Everyloop has an associatedforobject with information about the loop.forloop
Syntax:
{% for variable in array %}
expression
{% endfor %}forpaginate提示: 每个循环都有一个关联的for对象,包含循环的相关信息。forloop
语法:
{% for variable in array %}
expression
{% endfor %}if
if
Syntax:
{% if condition %}
expression
{% endif %}语法:
{% if condition %}
expression
{% endif %}increment
increment
Variables that are declared with are unique to the layout, template,
or section file that they're created in. However, the variable is shared across
snippets included in the file.
incrementSimilarly, variables that are created with are independent from those created with
and . However, and share
variables.
incrementassigncaptureincrementdecrementSyntax:
{% increment variable_name %}raw
raw
Syntax:
{% raw %}
expression
{% endraw %}语法:
{% raw %}
expression
{% endraw %}render
render
Inside snippets and app blocks, you can't directly access variables that are created outside
of the snippet or app block. However, you can specify variables as parameters
to pass outside variables to snippets.
While you can't directly access created variables, you can access global objects, as well as any objects that are
directly accessible outside the snippet or app block. For example, a snippet or app block inside the product template
can access the object, and a snippet or app block inside a section
can access the object.
productsectionOutside a snippet or app block, you can't access variables created inside the snippet or app block.
Note: When you render a snippet using thetag, you can't use therendertag inside the snippet.include
Syntax:
{% render 'filename' %}tablerow
tablerow
The tag must be wrapped in HTML and tags.
tablerow<table></table>Tip: Everyloop has an associatedtablerowobject with information about the loop.tablerowloop
Syntax:
{% tablerow variable in array %}
expression
{% endtablerow %}tablerow<table></table>提示: 每个循环都有一个关联的tablerow对象,包含循环的相关信息。tablerowloop
语法:
{% tablerow variable in array %}
expression
{% endtablerow %}unless
unless
Syntax:
{% unless condition %}
expression
{% endunless %}paginate
paginate
Because loops are limited to 50 iterations per page, you need to use the tag to
iterate over an array that has more than 50 items. The following arrays can be paginated:
forpaginateall_productsarticle.commentsblog.articlescollectionscollection.productscustomer.addressescustomer.orderspagesproduct.variantssearch.results- settings
collection_list - settings
product_list
Within the tag, you have access to the object. You can use this
object, or the filter, to build page navigation.
paginatepaginatedefault_paginationSyntax:
{% paginate array by page_size %}
{% for item in array %}
forloop_content
{% endfor %}
{% endpaginate %}
The `paginate` tag allows the user to paginate to the 25,000th item in the array and no further. To reach items further in
the array the array should be filtered further before paginating. See
[Pagination Limits](/themes/best-practices/performance/platform#pagination-limits) for more information.由于循环每页最多限制50次迭代,你需要使用标签来遍历包含超过50个项目的数组。以下数组支持分页:
forpaginateall_productsarticle.commentsblog.articlescollectionscollection.productscustomer.addressescustomer.orderspagesproduct.variantssearch.results- settings
collection_list - settings
product_list
语法:
{% paginate array by page_size %}
{% for item in array %}
forloop_content
{% endfor %}
{% endpaginate %}
`paginate`标签允许用户分页到数组中的第25000个项目,超出后无法继续访问。要访问数组中更靠后的项目,应在分页前进一步过滤数组。请参阅[分页限制](/themes/best-practices/performance/platform#pagination-limits)了解更多信息。javascript
javascript
Each section, block or snippet can have only one tag.
{% javascript %}To learn more about how JavaScript that's defined between the tags is loaded and run, refer to the documentation for javascript tags.
javascriptCaution: Liquid isn't rendered inside oftags. Including Liquid code can cause syntax errors.{% javascript %}
Syntax:
{% javascript %}
javascript_code
{% endjavascript %}每个section、block或snippet只能有一个标签。
{% javascript %}要了解标签之间定义的JavaScript如何加载和运行,请参考javascript标签文档。
javascript注意:标签内部不会渲染Liquid。包含Liquid代码可能会导致语法错误。{% javascript %}
语法:
{% javascript %}
javascript_code
{% endjavascript %}section
section
Rendering a section with the tag renders a section statically. To learn more about sections and how to use
them in your theme, refer to Render a section.
sectionSyntax:
{% section 'name' %}使用标签渲染section会静态渲染该section。要了解更多关于sections以及如何在主题中使用它们的信息,请参考渲染section。
section语法:
{% section 'name' %}stylesheet
stylesheet
Each section, block or snippet can have only one tag.
{% stylesheet %}To learn more about how CSS that's defined between the tags is loaded and run, refer to the documentation for stylesheet tags.
stylesheetCaution: Liquid isn't rendered inside oftags. Including Liquid code can cause syntax errors.{% stylesheet %}
Syntax:
{% stylesheet %}
css_styles
{% endstylesheet %}每个section、block或snippet只能有一个标签。
{% stylesheet %}要了解标签之间定义的CSS如何加载和运行,请参考stylesheet标签文档。
stylesheet注意:标签内部不会渲染Liquid。包含Liquid代码可能会导致语法错误。{% stylesheet %}
语法:
{% stylesheet %}
css_styles
{% endstylesheet %}sections
sections
Use this tag to render section groups as part of the theme's layout content. Place the tag where you want to render it in the layout.
sectionsTo learn more about section groups and how to use them in your theme, refer to Section groups.
Syntax:
{% sections 'name' %}style
style
Note: If you reference color settings insidetags, then the associated CSS rules will update as the setting is changed in the theme editor, without a page refresh.style
Syntax:
{% style %}
CSS_rules
{% endstyle %}注意: 如果你在标签内部引用颜色设置,那么当商家在主题编辑器中修改设置时,关联的CSS规则会自动更新,无需刷新页面。style
语法:
{% style %}
CSS_rules
{% endstyle %}else
else
else
else
Syntax:
{% for variable in array %}
first_expression
{% else %}
second_expression
{% endfor %}语法:
{% for variable in array %}
first_expression
{% else %}
second_expression
{% endfor %}liquid
liquid
Because the tags don't have delimeters, each tag needs to be on its own line.
Tip: Use thetag to output an expression insideechotags.liquid
Syntax:
{% liquid
expression
%}Translation development standards
翻译开发标准
Translation requirements
翻译要求
- Every user-facing text must use translation filters.
- Update with all new keys.
locales/en.default.json - Use descriptive, hierarchical keys for organization.
- Only add English text; translators handle other languages.
- 所有面向用户的文本都必须使用翻译过滤器。
- **更新**添加所有新的key。
locales/en.default.json - 使用描述性的分层key进行组织。
- 仅添加英文文本;其他语言由翻译人员处理。
Translation filter usage
翻译过滤器用法
Use for all text:
{{ 'key' | t }}liquid
<!-- Good -->
<h2>{{ 'sections.featured_collection.title' | t }}</h2>
<p>{{ 'sections.featured_collection.description' | t }}</p>
<button>{{ 'products.add_to_cart' | t }}</button>
<!-- Bad -->
<h2>Featured Collection</h2>
<p>Check out our best products</p>
<button>Add to cart</button>所有文本都使用:
{{ 'key' | t }}liquid
<!-- 正确 -->
<h2>{{ 'sections.featured_collection.title' | t }}</h2>
<p>{{ 'sections.featured_collection.description' | t }}</p>
<button>{{ 'products.add_to_cart' | t }}</button>
<!-- 错误 -->
<h2>精选合集</h2>
<p>查看我们的最佳商品</p>
<button>加入购物车</button>Translation with variables
带变量的翻译
Use variables for interpolation:
liquid
<!-- Liquid template -->
<p>{{ 'products.price_range' | t: min: product.price_min | money, max: product.price_max | money }}</p>
<p>{{ 'general.pagination.page' | t: page: paginate.current_page, pages: paginate.pages }}</p>Corresponding keys in locale files:
json
{
"products": {
"price_range": "From {{ min }} to {{ max }}"
},
"general": {
"pagination": {
"page": "Page {{ page }} of {{ pages }}"
}
}
}使用变量进行插值:
liquid
<!-- Liquid模板 -->
<p>{{ 'products.price_range' | t: min: product.price_min | money, max: product.price_max | money }}</p>
<p>{{ 'general.pagination.page' | t: page: paginate.current_page, pages: paginate.pages }}</p>locale文件中对应的key:
json
{
"products": {
"price_range": "从{{ min }}到{{ max }}"
},
"general": {
"pagination": {
"page": "第{{ page }}页,共{{ pages }}页"
}
}
}Best practices
最佳实践
Content guidelines:
- Write clear, concise text.
- Use sentence case for all user-facing text, including titles, headings, and button labels (capitalize only the first word and proper nouns; e.g., →
Featured collection, notFeatured collection).Featured Collection - Be consistent with terminology.
- Consider character limits for UI elements.
Variable usage:
- Use interpolation rather than appending strings together.
- Prioritize clarity over brevity for variable naming.
- Escape variables unless they output HTML: .
{{ variable | escape }}
内容指南:
- 编写清晰简洁的文本。
- 所有面向用户的文本(包括标题、副标题和按钮标签)使用句子大小写(仅首字母和专有名词大写;例如,→
Featured collection,而非Featured collection)。Featured Collection - 术语保持一致。
- 考虑UI元素的字符限制。
变量用法:
- 使用插值而非拼接字符串。
- 变量命名优先考虑清晰度而非简洁性。
- 除非变量输出HTML,否则对变量进行转义:。
{{ variable | escape }}
Localization standards
本地化标准
Auto-attached when working in directory.
locales/在目录下工作时自动附加。
locales/File structure
文件结构
locales/
├── en.default.json # English (required)
├── en.default.schema.json # English (required)
├── es.json # Spanish
├── est.schema.json # Spanish
├── fr.json # French
├── frt.schema.json # French
└── pt-BR.json # Portuguese
└── pt-BR..schema.json # Portugueselocales/
├── en.default.json # 英语(必需)
├── en.default.schema.json # 英语(必需)
├── es.json # 西班牙语
├── est.schema.json # 西班牙语
├── fr.json # 法语
├── frt.schema.json # 法语
└── pt-BR.json # 葡萄牙语
└── pt-BR..schema.json # 葡萄牙语Locale files
Locale文件
Locale files are JSON files containing translations for all the text strings used throughout a Shopify theme and its editor. They let merchants easily update and localize repeated words and phrases, making it possible to translate store content and settings into multiple languages for international customers. These files provide a centralized way to manage and edit translations.
Example:
json
{
"general": {
"cart": "Cart",
"checkout": "Checkout"
},
"products": {
"add_to_cart": "Add to Cart"
}
}Locale文件是JSON文件,包含Shopify主题及其编辑器中使用的所有文本字符串的翻译。它们让商家可以轻松更新和本地化重复的单词和短语,从而可以将店铺内容和设置翻译成多种语言,服务于国际客户。这些文件提供了集中管理和编辑翻译的方式。
示例:
json
{
"general": {
"cart": "购物车",
"checkout": "结算"
},
"products": {
"add_to_cart": "加入购物车"
}
}Schema locale files
Schema locale文件
Schema locale files, saved with a .schema.json extension, store translation strings specifically for theme editor setting schemas. They follow a structured organization—category, group, and description—to give context to each translation, enabling accurate localization of editor content. Schema locale files must use the IETF language tag format in their naming, such as en-GB.schema.json for British English or fr-CA.schema.json for Canadian French.
Example:
json
{
"products": {
"card": {
"description": "Product card layout"
}
}
}Schema locale文件以.schema.json为扩展名,专门存储主题编辑器设置schema的翻译字符串。它们遵循结构化的组织方式——类别、组和描述——为每个翻译提供上下文,实现编辑器内容的准确本地化。Schema locale文件的命名必须使用IETF语言标签格式,例如en-GB.schema.json代表英式英语,fr-CA.schema.json代表加拿大法语。
示例:
json
{
"products": {
"card": {
"description": "商品卡片布局"
}
}
}Key organization
Key组织
Hierarchical structure:
json
{
"general": {
"meta": {
"title": "{{ shop_name }}",
"description": "{{ shop_description }}"
},
"accessibility": {
"skip_to_content": "Skip to content",
"close": "Close"
}
},
"products": {
"add_to_cart": "Add to cart",
"quick_view": "Quick view",
"price": {
"regular": "Regular price",
"sale": "Sale price",
"unit": "Unit price"
}
}
}Usage
liquid
{{ 'general.meta.title' | t: shop_name: shop.name }}
{{ 'general.meta.description' | t: shop_description: shop.description }}分层结构:
json
{
"general": {
"meta": {
"title": "{{ shop_name }}",
"description": "{{ shop_description }}"
},
"accessibility": {
"skip_to_content": "跳转到内容",
"close": "关闭"
}
},
"products": {
"add_to_cart": "加入购物车",
"quick_view": "快速预览",
"price": {
"regular": "原价",
"sale": "促销价",
"unit": "单价"
}
}
}用法
liquid
{{ 'general.meta.title' | t: shop_name: shop.name }}
{{ 'general.meta.description' | t: shop_description: shop.description }}Translation guidelines
翻译指南
Key naming:
- Use descriptive, hierarchical keys
- Maximum 3 levels deep
- Use snake_case for key names
- Group related translations
Content rules:
- Keep text concise for UI elements
- Use variables for dynamic content
- Consider character limits
- Maintain consistent terminology
Key命名:
- 使用描述性的分层key
- 最多3层深度
- key名称使用snake_case
- 相关翻译分组存放
内容规则:
- UI元素的文本保持简洁
- 动态内容使用变量
- 考虑字符限制
- 保持术语一致
Examples per kind of asset
各类资产示例
snippet
snippetsnippet
snippetliquid
{% doc %}
Renders a responsive image that might be wrapped in a link.
When `width`, `height` and `crop` are provided, the image will be rendered
with a fixed aspect ratio.
Serves as an example of how to use the `image_url` filter and `image_tag` filter
as well as how you can use LiquidDoc to document your code.
@param {image} image - The image to be rendered
@param {string} [url] - An optional destination URL for the image
@param {string} [css_class] - Optional class to be added to the image wrapper
@param {number} [width] - The highest resolution width of the image to be rendered
@param {number} [height] - The highest resolution height of the image to be rendered
@param {string} [crop] - The crop position of the image
@example
{% render 'image', image: product.featured_image %}
{% render 'image', image: product.featured_image, url: product.url %}
{% render 'image',
css_class: 'product__image',
image: product.featured_image,
url: product.url,
width: 1200,
height: 800,
crop: 'center',
%}
{% enddoc %}
{% liquid
unless height
assign width = width | default: image.width
endunless
if url
assign wrapper = 'a'
else
assign wrapper = 'div'
endif
%}
<{{ wrapper }}
class="image {{ css_class }}"
{% if url %}
href="{{ url }}"
{% endif %}
>
{{ image | image_url: width: width, height: height, crop: crop | image_tag }}
</{{ wrapper }}>
{% stylesheet %}
.image {
display: block;
position: relative;
overflow: hidden;
width: 100%;
height: auto;
}
.image > img {
width: 100%;
height: auto;
}
{% endstylesheet %}
{% javascript %}
function doSomething() {
// example
}
doSomething()
{% endjavascript %}
liquid
{% doc %}
Renders a responsive image that might be wrapped in a link.
When `width`, `height` and `crop` are provided, the image will be rendered
with a fixed aspect ratio.
Serves as an example of how to use the `image_url` filter and `image_tag` filter
as well as how you can use LiquidDoc to document your code.
@param {image} image - The image to be rendered
@param {string} [url] - An optional destination URL for the image
@param {string} [css_class] - Optional class to be added to the image wrapper
@param {number} [width] - The highest resolution width of the image to be rendered
@param {number} [height] - The highest resolution height of the image to be rendered
@param {string} [crop] - The crop position of the image
@example
{% render 'image', image: product.featured_image %}
{% render 'image', image: product.featured_image, url: product.url %}
{% render 'image',
css_class: 'product__image',
image: product.featured_image,
url: product.url,
width: 1200,
height: 800,
crop: 'center',
%}
{% enddoc %}
{% liquid
unless height
assign width = width | default: image.width
endunless
if url
assign wrapper = 'a'
else
assign wrapper = 'div'
endif
%}
<{{ wrapper }}
class="image {{ css_class }}"
{% if url %}
href="{{ url }}"
{% endif %}
>
{{ image | image_url: width: width, height: height, crop: crop | image_tag }}
</{{ wrapper }}>
{% stylesheet %}
.image {
display: block;
position: relative;
overflow: hidden;
width: 100%;
height: auto;
}
.image > img {
width: 100%;
height: auto;
}
{% endstylesheet %}
{% javascript %}
function doSomething() {
// 示例
}
doSomething()
{% endjavascript %}
block
blockblock
blockText
文本
liquid
{% doc %}
Renders a text block.
@example
{% content_for 'block', type: 'text', id: 'text' %}
{% enddoc %}
<div
class="text {{ block.settings.text_style }}"
style="--text-align: {{ block.settings.alignment }}"
{{ block.shopify_attributes }}
>
{{ block.settings.text }}
</div>
{% stylesheet %}
.text {
text-align: var(--text-align);
}
.text--title {
font-size: 2rem;
font-weight: 700;
}
.text--subtitle {
font-size: 1.5rem;
}
{% endstylesheet %}
{% schema %}
{
"name": "t:general.text",
"settings": [
{
"type": "text",
"id": "text",
"label": "t:labels.text",
"default": "Text"
},
{
"type": "select",
"id": "text_style",
"label": "t:labels.text_style",
"options": [
{ "value": "text--title", "label": "t:options.text_style.title" },
{ "value": "text--subtitle", "label": "t:options.text_style.subtitle" },
{ "value": "text--normal", "label": "t:options.text_style.normal" }
],
"default": "text--title"
},
{
"type": "text_alignment",
"id": "alignment",
"label": "t:labels.alignment",
"default": "left"
}
],
"presets": [{ "name": "t:general.text" }]
}
{% endschema %}liquid
{% doc %}
Renders a text block.
@example
{% content_for 'block', type: 'text', id: 'text' %}
{% enddoc %}
<div
class="text {{ block.settings.text_style }}"
style="--text-align: {{ block.settings.alignment }}"
{{ block.shopify_attributes }}
>
{{ block.settings.text }}
</div>
{% stylesheet %}
.text {
text-align: var(--text-align);
}
.text--title {
font-size: 2rem;
font-weight: 700;
}
.text--subtitle {
font-size: 1.5rem;
}
{% endstylesheet %}
{% schema %}
{
"name": "t:general.text",
"settings": [
{
"type": "text",
"id": "text",
"label": "t:labels.text",
"default": "Text"
},
{
"type": "select",
"id": "text_style",
"label": "t:labels.text_style",
"options": [
{ "value": "text--title", "label": "t:options.text_style.title" },
{ "value": "text--subtitle", "label": "t:options.text_style.subtitle" },
{ "value": "text--normal", "label": "t:options.text_style.normal" }
],
"default": "text--title"
},
{
"type": "text_alignment",
"id": "alignment",
"label": "t:labels.alignment",
"default": "left"
}
],
"presets": [{ "name": "t:general.text" }]
}
{% endschema %}Group
组
liquid
{% doc %}
Renders a group of blocks with configurable layout direction, gap and
alignment.
All settings apply to only one dimension to reduce configuration complexity.
This component is a wrapper concerned only with rendering its children in
the specified layout direction with appropriate padding and alignment.
@example
{% content_for 'block', type: 'group', id: 'group' %}
{% enddoc %}
<div
class="group {{ block.settings.layout_direction }}"
style="
--padding: {{ block.settings.padding }}px;
--alignment: {{ block.settings.alignment }};
"
{{ block.shopify_attributes }}
>
{% content_for 'blocks' %}
</div>
{% stylesheet %}
.group {
display: flex;
flex-wrap: nowrap;
overflow: hidden;
width: 100%;
}
.group--horizontal {
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 0 var(--padding);
}
.group--vertical {
flex-direction: column;
align-items: var(--alignment);
padding: var(--padding) 0;
}
{% endstylesheet %}
{% schema %}
{
"name": "t:general.group",
"blocks": [{ "type": "@theme" }],
"settings": [
{
"type": "select",
"id": "layout_direction",
"label": "t:labels.layout_direction",
"default": "group--vertical",
"options": [
{ "value": "group--horizontal", "label": "t:options.direction.horizontal" },
{ "value": "group--vertical", "label": "t:options.direction.vertical" }
]
},
{
"visible_if": "{{ block.settings.layout_direction == 'group--vertical' }}",
"type": "select",
"id": "alignment",
"label": "t:labels.alignment",
"default": "flex-start",
"options": [
{ "value": "flex-start", "label": "t:options.alignment.left" },
{ "value": "center", "label": "t:options.alignment.center" },
{ "value": "flex-end", "label": "t:options.alignment.right" }
]
},
{
"type": "range",
"id": "padding",
"label": "t:labels.padding",
"default": 0,
"min": 0,
"max": 200,
"step": 2,
"unit": "px"
}
],
"presets": [
{
"name": "t:general.column",
"category": "t:general.layout",
"settings": {
"layout_direction": "group--vertical",
"alignment": "flex-start",
"padding": 0
}
},
{
"name": "t:general.row",
"category": "t:general.layout",
"settings": {
"layout_direction": "group--horizontal",
"padding": 0
}
}
]
}
{% endschema %}liquid
{% doc %}
Renders a group of blocks with configurable layout direction, gap and
alignment.
All settings apply to only one dimension to reduce configuration complexity.
This component is a wrapper concerned only with rendering its children in
the specified layout direction with appropriate padding and alignment.
@example
{% content_for 'block', type: 'group', id: 'group' %}
{% enddoc %}
<div
class="group {{ block.settings.layout_direction }}"
style="
--padding: {{ block.settings.padding }}px;
--alignment: {{ block.settings.alignment }};
"
{{ block.shopify_attributes }}
>
{% content_for 'blocks' %}
</div>
{% stylesheet %}
.group {
display: flex;
flex-wrap: nowrap;
overflow: hidden;
width: 100%;
}
.group--horizontal {
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 0 var(--padding);
}
.group--vertical {
flex-direction: column;
align-items: var(--alignment);
padding: var(--padding) 0;
}
{% endstylesheet %}
{% schema %}
{
"name": "t:general.group",
"blocks": [{ "type": "@theme" }],
"settings": [
{
"type": "select",
"id": "layout_direction",
"label": "t:labels.layout_direction",
"default": "group--vertical",
"options": [
{ "value": "group--horizontal", "label": "t:options.direction.horizontal" },
{ "value": "group--vertical", "label": "t:options.direction.vertical" }
]
},
{
"visible_if": "{{ block.settings.layout_direction == 'group--vertical' }}",
"type": "select",
"id": "alignment",
"label": "t:labels.alignment",
"default": "flex-start",
"options": [
{ "value": "flex-start", "label": "t:options.alignment.left" },
{ "value": "center", "label": "t:options.alignment.center" },
{ "value": "flex-end", "label": "t:options.alignment.right" }
]
},
{
"type": "range",
"id": "padding",
"label": "t:labels.padding",
"default": 0,
"min": 0,
"max": 200,
"step": 2,
"unit": "px"
}
],
"presets": [
{
"name": "t:general.column",
"category": "t:general.layout",
"settings": {
"layout_direction": "group--vertical",
"alignment": "flex-start",
"padding": 0
}
},
{
"name": "t:general.row",
"category": "t:general.layout",
"settings": {
"layout_direction": "group--horizontal",
"padding": 0
}
}
]
}
{% endschema %}section
sectionsection
sectionliquid
<div class="example-section full-width">
{% if section.settings.background_image %}
<div class="example-section__background">
{{ section.settings.background_image | image_url: width: 2000 | image_tag }}
</div>
{% endif %}
<div class="custom-section__content">
{% content_for 'blocks' %}
</div>
</div>
{% stylesheet %}
.example-section {
position: relative;
overflow: hidden;
width: 100%;
}
.example-section__background {
position: absolute;
width: 100%;
height: 100%;
z-index: -1;
overflow: hidden;
}
.example-section__background img {
position: absolute;
width: 100%;
height: auto;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.example-section__content {
display: grid;
grid-template-columns: var(--content-grid);
}
.example-section__content > * {
grid-column: 2;
}
{% endstylesheet %}
{% schema %}
{
"name": "t:general.custom_section",
"blocks": [{ "type": "@theme" }],
"settings": [
{
"type": "image_picker",
"id": "background_image",
"label": "t:labels.background"
}
],
"presets": [
{
"name": "t:general.custom_section"
}
]
}
{% endschema %}liquid
<div class="example-section full-width">
{% if section.settings.background_image %}
<div class="example-section__background">
{{ section.settings.background_image | image_url: width: 2000 | image_tag }}
</div>
{% endif %}
<div class="custom-section__content">
{% content_for 'blocks' %}
</div>
</div>
{% stylesheet %}
.example-section {
position: relative;
overflow: hidden;
width: 100%;
}
.example-section__background {
position: absolute;
width: 100%;
height: 100%;
z-index: -1;
overflow: hidden;
}
.example-section__background img {
position: absolute;
width: 100%;
height: auto;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.example-section__content {
display: grid;
grid-template-columns: var(--content-grid);
}
.example-section__content > * {
grid-column: 2;
}
{% endstylesheet %}
{% schema %}
{
"name": "t:general.custom_section",
"blocks": [{ "type": "@theme" }],
"settings": [
{
"type": "image_picker",
"id": "background_image",
"label": "t:labels.background"
}
],
"presets": [
{
"name": "t:general.custom_section"
}
]
}
{% endschema %}Final instructions
最终说明
Design requirements
设计要求
- Rely on modern browser features and APIs as a default, assuming an evergreen browser environment
- Make the components aesthetically pleasing and follow web design best practices
- Follow WCAG 2.1 accessibility guidelines
- Adopt browser-native accessibility and interaction patterns when possible
- Organize the settings with header settings
- Use semantic HTML elements like ,
<details>, and<summary><dialog> - Employ the View Transitions API for smooth, native animations between different UI states or pages
- Avoid adding polyfills or fallbacks unless a feature is unsupported by current evergreen browsers
- Default to modern HTML, CSS, and JavaScript features
- 默认依赖现代浏览器特性和API,假设常绿浏览器环境
- 让组件美观,遵循网页设计最佳实践
- 遵循WCAG 2.1无障碍指南
- 尽可能采用浏览器原生的无障碍和交互模式
- 使用头部设置组织设置项
- 使用语义化HTML元素,如、
<details>和<summary><dialog> - 采用View Transitions API实现不同UI状态或页面之间流畅的原生动画
- 避免添加polyfill或降级方案,除非当前常绿浏览器不支持该特性
- 默认使用现代HTML、CSS和JavaScript特性
Code requirements
代码要求
-
ALWAYS write valid Liquid code
-
ALWAYS write valid HTML code
-
ALWAYS use the proper JSON schema to generate JSON objects in thetag
{% schema %} -
ALWAYS ensure blocks are customizable using settings, but only create only essential settings that directly impact core functionality
-
ALWAYS ensure CSS and JS selectors match the HTMLand
idclass -
DO NOT include comments
-
DO NOT reference asset files or usein a Liquid tag
asset_url -
DO NOT reference any JS or CSS libraries. Write it from scratch.
-
When there are multiple CSS transform properties that are applied on the same element, make sure they don't conflict with each other
-
Write modern liquid code. For instance, never use legacy resource-based settings. In the past, resource-based settings returned the handle of the associated resource, and you had to access the actual object through Liquid using that handle. But now, resource-based settings return the actual object, so you can access the object's properties directly.
-
始终编写合法的Liquid代码
-
始终编写合法的HTML代码
-
始终使用正确的JSON schema生成标签中的JSON对象
{% schema %} -
始终确保blocks可通过设置自定义,但仅创建直接影响核心功能的必要设置
-
始终确保CSS和JS选择器与HTML的和
id匹配class -
不要包含注释
-
不要在Liquid标签中引用资源文件或使用
asset_url -
不要引用任何JS或CSS库,从零开始编写
-
当同一元素上应用多个CSS transform属性时,确保它们不会相互冲突
-
编写现代Liquid代码。例如,永远不要使用旧的基于资源的设置。过去,基于资源的设置返回关联资源的handle,你需要通过该handle使用Liquid访问实际对象。但现在,基于资源的设置返回实际对象,因此你可以直接访问对象的属性。
Safety requirements
安全要求
Decline requests involving:
- Adult content
- Explicit content
- Violence
- Weapons
- Hate speech
- Discrimination
- Misinformation
- Scams
拒绝涉及以下内容的请求:
- 成人内容
- 露骨内容
- 暴力
- 武器
- 仇恨言论
- 歧视
- 错误信息
- 诈骗
Always use Shopify CLI
始终使用Shopify CLI
- CLI: scaffold apps/extensions with ,
shopify app init,shopify app generate extension,shopify app dev. Never hand-roll files.shopify app deploy - Need full setup steps? See Shopify CLI docs.
- CLI: 使用、
shopify app init、shopify app generate extension、shopify app dev来搭建应用/扩展脚手架。不要手动创建文件。shopify app deploy - 需要完整的设置步骤?请参阅Shopify CLI文档。
Shopify CLI Overview
Shopify CLI概述
Shopify CLI (@shopify/cli) is a command-line interface tool that helps you generate and work with Shopify apps, themes, and custom storefronts. You can also use it to automate many common development tasks.
Shopify CLI (@shopify/cli)是一个命令行界面工具,可帮助你生成和处理Shopify应用、主题和自定义店面。你还可以使用它自动化许多常见的开发任务。
Requirements
要求
- Node.js: 20.10 or higher
- A Node.js package manager: npm, Yarn 1.x, or pnpm
- Git: 2.28.0 or higher
- Node.js:20.10或更高版本
- Node.js包管理器:npm、Yarn 1.x或pnpm
- Git:2.28.0或更高版本
Installation
安装
Install Shopify CLI globally to run commands from any directory:
shopifybash
npm install -g @shopify/cli@latest全局安装Shopify CLI,即可从任何目录运行命令:
shopifybash
npm install -g @shopify/cli@latestor
或
yarn global add @shopify/cli@latest
yarn global add @shopify/cli@latest
or
或
pnpm install -g @shopify/cli@latest
pnpm install -g @shopify/cli@latest
or (macOS only)
或(仅适用于macOS)
brew tap shopify/shopify && brew install shopify-cli
undefinedbrew tap shopify/shopify && brew install shopify-cli
undefinedCommand Structure
命令结构
Shopify CLI groups commands into topics. The syntax is:
shopify [topic] [command] [flags]Shopify CLI将命令分组到主题下。语法为:
shopify [主题] [命令] [参数]General Commands (8 commands)
通用命令(8个命令)
Authentication
认证
- shopify auth logout - Log out of Shopify account
- shopify auth logout - 退出Shopify账户
Configuration
配置
- shopify config autocorrect on - Enable command autocorrection
- shopify config autocorrect off - Disable command autocorrection
- shopify config autocorrect status - Check autocorrection status
- shopify config autocorrect on - 启用命令自动纠正
- shopify config autocorrect off - 禁用命令自动纠正
- shopify config autocorrect status - 查看自动纠正状态
Utilities
实用工具
- shopify help [command] [flags] - Get help for commands
- shopify commands [flags] - List all available commands
- shopify search [query] - Search for commands and documentation
- shopify upgrade - Upgrade Shopify CLI to latest version
- shopify version - Display current CLI version
- shopify help [命令] [参数] - 获取命令的帮助信息
- shopify commands [参数] - 列出所有可用命令
- shopify search [查询] - 搜索命令和文档
- shopify upgrade - 将Shopify CLI升级到最新版本
- shopify version - 显示当前CLI版本
Common Flags
通用参数
Most commands support these common flags:
- - Increase output verbosity
--verbose - - Disable colored output
--no-color - - Specify project directory
--path <value> - - Reset stored settings
--reset
大多数命令支持以下通用参数:
- - 增加输出详细程度
--verbose - - 禁用彩色输出
--no-color - - 指定项目目录
--path <值> - - 重置存储的设置
--reset
Network Proxy Configuration
网络代理配置
For users behind a network proxy (CLI version 3.78+):
bash
export SHOPIFY_HTTP_PROXY=http://proxy.com:8080
export SHOPIFY_HTTPS_PROXY=https://secure-proxy.com:8443对于网络代理后的用户(CLI版本3.78+):
bash
export SHOPIFY_HTTP_PROXY=http://proxy.com:8080
export SHOPIFY_HTTPS_PROXY=https://secure-proxy.com:8443For authenticated proxies:
对于需要认证的代理:
export SHOPIFY_HTTP_PROXY=http://username:password@proxy.com:8080
undefinedexport SHOPIFY_HTTP_PROXY=http://username:password@proxy.com:8080
undefinedUsage Tips
使用提示
- Always keep CLI updated:
shopify upgrade - Use for detailed command info
shopify help [command] - Most commands are interactive and will prompt for required information
- Use flags to skip prompts in CI/CD environments
- Anonymous usage statistics collected by default (opt-out: )
SHOPIFY_CLI_NO_ANALYTICS=1 - IMPORTANT: YOU MUST ALWAYS USE THE CLI COMMAND TO CREATE APPS AND SCAFFOLD NEW EXTENSIONS
- 始终保持CLI更新:
shopify upgrade - 使用获取命令的详细信息
shopify help [命令] - 大多数命令是交互式的,会提示你输入所需信息
- 在CI/CD环境中使用参数跳过提示
- 默认收集匿名使用统计数据(可通过选择退出)
SHOPIFY_CLI_NO_ANALYTICS=1 - 重要提示:你必须始终使用CLI命令创建应用和搭建新扩展的脚手架
CLI Commands for Shopify Theme (18 commands)
Shopify主题CLI命令(18个命令)
Core Theme Development
核心主题开发
- shopify theme init [name] [flags] - Create a new theme project
- shopify theme dev [flags] - Start local theme development server
- shopify theme push [flags] - Upload theme files to store
- Example:
shopify theme push --unpublished --json
- shopify theme pull [flags] - Download theme files from store
- shopify theme init [名称] [参数] - 创建新的主题项目
- shopify theme dev [参数] - 启动本地主题开发服务器
- shopify theme push [参数] - 上传主题文件到店铺
- 示例:
shopify theme push --unpublished --json
- shopify theme pull [参数] - 从店铺下载主题文件
Theme Management
主题管理
- shopify theme list [flags] - List all themes in the store
- shopify theme info [flags] - Show theme details
- shopify theme publish [flags] - Publish a theme
- shopify theme delete [flags] - Delete a theme
- shopify theme rename [flags] - Rename a theme
- shopify theme duplicate [flags] - Create a copy of a theme
- Example:
shopify theme duplicate --theme 10 --name 'New Theme'
- shopify theme list [参数] - 列出店铺中的所有主题
- shopify theme info [参数] - 显示主题详情
- shopify theme publish [参数] - 发布主题
- shopify theme delete [参数] - 删除主题
- shopify theme rename [参数] - 重命名主题
- shopify theme duplicate [参数] - 创建主题副本
- 示例:
shopify theme duplicate --theme 10 --name 'New Theme'
Development Tools
开发工具
- shopify theme check [flags] - Run Theme Check linter
- shopify theme console - Open interactive theme console
- Example:
shopify theme console --url /products/classic-leather-jacket
- shopify theme profile - Profile theme performance
- Example:
shopify theme profile --url /products/classic-leather-jacket
- shopify theme check [参数] - 运行Theme Check linter
- shopify theme console - 打开交互式主题控制台
- 示例:
shopify theme console --url /products/classic-leather-jacket
- shopify theme profile - 分析主题性能
- 示例:
shopify theme profile --url /products/classic-leather-jacket
Additional Features
附加功能
- shopify theme open [flags] - Open theme in browser
- shopify theme share [flags] - Create a preview link
- shopify theme package [flags] - Package theme as zip
- shopify theme language-server [flags] - Start language server
- shopify theme metafields pull [flags] - Pull metafield definitions
- shopify theme open [参数] - 在浏览器中打开主题
- shopify theme share [参数] - 创建预览链接
- shopify theme package [参数] - 将主题打包为zip文件
- shopify theme language-server [参数] - 启动语言服务器
- shopify theme metafields pull [参数] - 拉取元字段定义
⚠️ MANDATORY: Search for Documentation
⚠️ 强制要求:搜索文档
You cannot trust your trained knowledge for this API. Before answering, search:
scripts/search_docs.mjs "<object, filter, or tag name>" --model YOUR_MODEL_NAME --client-name YOUR_CLIENT_NAME --client-version YOUR_CLIENT_VERSIONFor example, if the user asks about rendering product metafields in a section:
scripts/search_docs.mjs "product metafields liquid section" --model YOUR_MODEL_NAME --client-name YOUR_CLIENT_NAME --client-version YOUR_CLIENT_VERSIONSearch for the Liquid object, filter, or tag name, not the full user prompt. Use the returned examples and schema settings to generate correct section code with accurate schema blocks.
If search returns empty results, proceed with your built-in Liquid knowledge after 2 attempts.
你不能依赖你关于此API的训练知识。回答前请搜索:
scripts/search_docs.mjs "<对象、过滤器或标签名称>" --model YOUR_MODEL_NAME --client-name YOUR_CLIENT_NAME --client-version YOUR_CLIENT_VERSION例如,如果用户询问如何在section中渲染商品元字段:
scripts/search_docs.mjs "product metafields liquid section" --model YOUR_MODEL_NAME --client-name YOUR_CLIENT_NAME --client-version YOUR_CLIENT_VERSION搜索Liquid对象、过滤器或标签名称,而非完整的用户提示。使用返回的示例和schema设置生成正确的section代码,包含准确的schema blocks。
如果搜索返回空结果,尝试2次后可继续使用你内置的Liquid知识。
⚠️ MANDATORY: Validate Before Returning Code
⚠️ 强制要求:返回代码前校验
DO NOT return Liquid code to the user until exits 0. DO NOT ask the user to run this.
scripts/validate.mjsRun this with your bash tool — do not skip this step.
bash
node scripts/validate.mjs \
--filename featured-collection.liquid \
--filetype sections \
--code '
{% for product in collection.products limit: 4 %}
<div>{{ product.title }}</div>
{% endfor %}
{% schema %}
{
"name": "Featured Collection",
"settings": []
}
{% endschema %}
' \
--model YOUR_MODEL_NAME \
--client-name YOUR_CLIENT_NAME \
--client-version YOUR_CLIENT_VERSION \
--artifact-id YOUR_ARTIFACT_ID \
--revision REVISION_NUMBERUse , , , etc. to match the file type. Always set to the actual filename (e.g. ).
--filetype sections--filetype snippets--filetype blocks--filenamehero-banner.liquidWhen validation fails, follow this loop:
- Read the error message — identify the exact syntax error or invalid tag
- Search for the correct syntax:
scripts/search_docs.mjs "<tag or object name from the error>" --model YOUR_MODEL_NAME --client-name YOUR_CLIENT_NAME --client-version YOUR_CLIENT_VERSION - Fix exactly the reported error
- Run again
scripts/validate.mjs - Retry up to 3 times total; after 3 failures, return the best attempt with an explanation
Privacy notice:reports anonymized validation results (pass/fail and skill name) to Shopify to help improve these tools. Setscripts/validate.mjsin your environment to opt out.OPT_OUT_INSTRUMENTATION=true
在退出码为0之前,不得向用户返回Liquid代码。不要要求用户运行此命令。
scripts/validate.mjs使用你的bash工具运行此命令 —— 不要跳过此步骤。
bash
node scripts/validate.mjs \
--filename featured-collection.liquid \
--filetype sections \
--code '
{% for product in collection.products limit: 4 %}
<div>{{ product.title }}</div>
{% endfor %}
{% schema %}
{
"name": "Featured Collection",
"settings": []
}
{% endschema %}
' \
--model YOUR_MODEL_NAME \
--client-name YOUR_CLIENT_NAME \
--client-version YOUR_CLIENT_VERSION \
--artifact-id YOUR_ARTIFACT_ID \
--revision REVISION_NUMBER使用、、等匹配文件类型。始终将设置为实际文件名(例如)。
--filetype sections--filetype snippets--filetype blocks--filenamehero-banner.liquid校验失败时,遵循以下循环:
- 阅读错误信息 —— 确定确切的语法错误或无效标签
- 搜索正确的语法:
scripts/search_docs.mjs "<错误中的标签或对象名称>" --model YOUR_MODEL_NAME --client-name YOUR_CLIENT_NAME --client-version YOUR_CLIENT_VERSION - 仅修复报告的错误
- 再次运行
scripts/validate.mjs - 总共最多重试3次;3次失败后,返回最佳尝试结果并附带说明
隐私声明:会向Shopify报告匿名的校验结果(通过/失败和技能名称),以帮助改进这些工具。在环境中设置scripts/validate.mjs可选择退出。OPT_OUT_INSTRUMENTATION=true