User 69e88e27
发布于:2025-04-11
用于站点pages的数据过滤
query 标签的基本语法:{% query 结果变量名 from site.pages %}
JSON格式的查询条件
{% endquery %}\\ 进行转义。例如:"title": "这是一个\"示例\"标题"。\\,需要进行双重转义,即使用 \\\\。例如:"path": "C:\\\\Users\\\\Example"。\\n、制表符 \\t 等。{% query faq_pages from site.pages %}
{
"where": {
"template_name_eq": "page",
"settings.var_name_matches": params.any_string,
"settings.description_start": "帮助"
},
"order_by": ["-created_at"],
"limit": 10,
"offset": 0
}
{% endquery %}
<!-- 使用筛选后的结果 -->
{% for page in faq_pages %}
<a href="{{ page.url }}">{{ page.title }}</a>
{% endfor %}
whereand 和 or。"where": {
"属性名_操作符": 值,
"settings.变量名_操作符": 值,
"settings.模版文件完整路径:变量名_操作符": 值, // 指定检索使用某模版创建的页面中动态变量的数据
"and": {
// 嵌套的AND条件
},
"or": {
// 嵌套的OR条件
}
}
"where": {
"template_name_eq": "product",
"or": {
"name_start": "文章标题",
"settings.description_cont": "智能设备"
}
}
order_by["字段名", ...]。"created_at"- 前缀,如 "-created_at"created_at: 创建时间visits_count: 访问次数edited_at: 编辑时间published_at: 发布时间"order_by": ["-visits_count", "created_at"]
limit 和 offset"limit": 10,
"offset": 20
{% assign page_size = 10 %}
{% assign current_page = params.page | default: 1 | floor %}
{% assign offset = page_size | times: current_page | minus: page_size %}
{% query paginated_results from site.pages %}
{
"where": { "template_name_eq": "article" },
"limit": {{ page_size }},
"offset": {{ offset }},
"order_by": ["-created_at"]
}
{% endquery %}
模板名:变量名_操作符 构成(如:description_start, 'templates/index.list.liquid:description_start')。OR 合并查询。queryable: true 才支持该字段筛选。settings_schema 中添加 queryable: true:{% schema %}
{
"name": "Help Center",
"settings": [
{
"id": "description",
"type": "textarea",
"label": "描述",
"queryable": true
}
]
}
{% endschema %}
settings_type(表单类型) | 数据类型 |
|---|---|
checkbox | boolean |
color, color_background, font_picker, image_picker, link, radio, select, tag_picker, text, video_picker | multiple = true ? array : string |
date | date |
html, richtext, textarea | text |
number, range | float |
属性名_操作符 构成(如:visits_count_gt, 'created_at_lteq')。属性名 | 说明 | 数据类型 |
|---|---|---|
name | 页面名称(计算后实际展示的值) | string |
visits_count | 访问次数 | integer |
full_path | 完整路径 | string |
template_name | 模板名称 | string |
template_style | 模板样式 | string |
updated_at | 页面更新时间 | datetime |
created_at | 页面创建时间 | datetime |
| 操作符 | 含义 | 适用类型 | 例如 |
|--------|------|----------|------|
| `eq` | 等于 | 所有类型 | `"name_eq": "产品"` |
| `not_eq` | 不等于 | 所有类型 | `"name_not_eq": "产品"` |
| `lt` | 小于 | 数值、日期 | `"visits_count_lt": 100` |
| `gt` | 大于 | 数值、日期 | `"visits_count_gt": 100` |
| `lteq` | 小于等于 | 数值、日期 | `"created_at_lteq": "2023-01-01"` |
| `gteq` | 大于等于 | 数值、日期 | `"created_at_gteq": "2023-01-01"` |
| `cont` | 包含(区分大小写) | 字符串 | `"title_cont": "关键词"` |
| `i_cont` | 包含(忽略大小写) | 字符串 | `"title_i_cont": "关键词"` |
| `not_cont` | 不包含(区分大小写) | 字符串 | `"title_not_cont": "关键词"` |
| `not_i_cont` | 不包含(忽略大小写) | 字符串 | `"title_not_i_cont": "关键词"` |
| `start` | 以...开头 | 字符串 | `"name_start": "产品"` |
| `not_start` | 不以...开头 | 字符串 | `"name_not_start": "产品"` |
| `end` | 以...结尾 | 字符串 | `"name_end": "产品"` |
| `not_end` | 不以...结尾 | 字符串 | `"name_not_end": "产品"` |
| `matches` | 正则匹配 | 字符串 | `"name_matches": "^产品.*"` |
| `does_not_match` | 正则不匹配 | 字符串 | `"name_does_not_match": "^产品.*"` |
| `matches_any` | 任意正则匹配 | 字符串 | `"name_matches_any": ["^产品.*", ".*服务$"]` |
| `matches_all` | 所有正则匹配 | 字符串 | `"name_matches_all": ["^产品.*", ".*服务$"]` |
| `does_not_match_any` | 任意正则不匹配 | 字符串 | `"name_does_not_match_any": ["^产品.*", ".*服务$"]` |
| `does_not_match_all` | 所有正则不匹配 | 字符串 | `"name_does_not_match_all": ["^产品.*", ".*服务$"]` |
| `in` | 在集合中 | 字符串 | `"name_in": ["产品1", "产品2"]` |
| `not_in` | 不在集合中 | 字符串 | `"name_not_in": ["产品1", "产品2"]` |
| `start_any` | 任意以...开头 | 字符串 | `"name_start_any": ["产品", "服务"]` |
| `start_all` | 所有以...开头 | 字符串 | `"name_start_all": ["产品", "服务"]` |
| `not_start_any` | 任意不以...开头 | 字符串 | `"name_not_start_any": ["产品", "服务"]` |
| `not_start_all` | 所有不以...开头 | 字符串 | `"name_not_start_all": ["产品", "服务"]` |
| `end_any` | 任意以...结尾 | 字符串 | `"name_end_any": ["产品", "服务"]` |
| `end_all` | 所有以...结尾 | 字符串 | `"name_end_all": ["产品", "服务"]` |
| `not_end_any` | 任意不以...结尾 | 字符串 | `"name_not_end_any": ["产品", "服务"]` |
| `not_end_all` | 所有不以...结尾 | 字符串 | `"name_not_end_all": ["产品", "服务"]` |
| `cont_any` | 任意包含(区分大小写) | 字符串 | `"name_cont_any": ["产品", "服务"]` |
| `cont_all` | 所有包含(区分大小写) | 字符串 | `"name_cont_all": ["产品", "服务"]` |
| `not_cont_any` | 任意不包含(区分大小写) | 字符串 | `"name_not_cont_any": ["产品", "服务"]` |
| `not_cont_all` | 所有不包含(区分大小写) | 字符串 | `"name_not_cont_all": ["产品", "服务"]` |
| `i_cont_any` | 任意包含(忽略大小写) | 字符串 | `"name_i_cont_any": ["产品", "服务"]` |
| `i_cont_all` | 所有包含(忽略大小写) | 字符串 | `"name_i_cont_all": ["产品", "服务"]` |
| `not_i_cont_any` | 任意不包含(忽略大小写) | 字符串 | `"name_not_i_cont_any": ["产品", "服务"]` |
| `not_i_cont_all` | 所有不包含(忽略大小写) | 字符串 | `"name_not_i_cont_all": ["产品", "服务"]` |
| `true` | 为真 | 布尔值 | `"is_active_true": true` |
| `false` | 为假 | 布尔值 | `"is_active_false": false` |
| `array_cont_all` | 包含所有指定值 | 数组 | `"array_cont_all": ["热门", "促销"]` |
| `not_array_cont_all` | 不包含所有指定值 | 数组 | `"not_array_cont_all": ["热门", "促销"]` |
| `array_cont_any` | 包含任一指定值 | 数组 | `"array_cont_any": ["热门", "促销"]` |
| `not_array_cont_any` | 不包含任一指定值 | 数组 | `"not_array_cont_any": ["热门", "促销"]` |
| `array_equals` | 数组完全相等 | 数组 | `"array_equals": ["热门", "促销"]` |
| `not_array_equals` | 数组不完全相等 | 数组 | `"not_array_equals": ["热门", "促销"]` |数据类型 | 支持的操作符 |
|---|---|
boolean | true, false, eq |
string | eq not_eq matches does_not_match matches_any matches_all does_not_match_any does_not_match_all in not_in start not_start start_any start_all not_start_any not_start_all end not_end end_any end_all not_end_any not_end_all cont cont_any cont_all not_cont not_cont_any not_cont_all i_cont i_cont_any i_cont_all not_i_cont not_i_cont_any not_i_cont_all |
text | i_cont cont not_i_cont not_cont eq not_eq start not_start end not_end |
date / datetime | eq, not_eq, lt, gt, lteq, gteq |
float / integer | eq, not_eq, lt, gt, lteq, gteq |
array | array_cont_all, not_array_cont_all, array_cont_any, not_array_cont_any, array_equals, not_array_equals |
{% query featured_products from site.pages %}
{
"where": {
"and": {
"template_name_eq": "product",
"settings.featured_true": true
},
"or": {
"settings.category_eq": "电子产品",
"settings.tags_contains_any": ["热门", "促销"]
}
},
"order_by": ["visits_count"],
"limit": 5,
"offset": 0
}
{% endquery %}
{% for product in featured_products %}
<div class="product">
<h3>{{ product.title }}</h3>
<p>{{ product.settings.description }}</p>
<a href="{{ product.url }}">查看详情</a>
</div>
{% endfor %}