为任意区块添加字段
纯JSON。无需模板,也无需渲染回调。
自定义字段,无需模板
创建一个JSON文件,使用name指定目标区块,并定义字段。set会将值映射到类、样式、数据属性或任何其他HTML属性。
Blockstudio使用WordPressHTML标签处理器应用输出。无需模板,也无需渲染回调。
{
"name": "core/*",
"blockstudio": {
"extend": { "priority": 10 },
"attributes": [
{
"id": "animation",
"type": "select",
"allowNull": "None",
"options": [
{ "value": "fade", "label": "Fade" },
{ "value": "slide", "label": "Slide" }
],
"set": [{
"attribute": "class",
"value": "animate-{attributes.animation}"
}]
}
]
}
}指定任意区块
扩展一个区块、一份列表或带通配符的命名空间。
set 属性
将字段映射到类、样式、数据属性或任何HTML属性。
条件字段
根据其他值,使用类似区块的逻辑显示字段。
完整功能集
涵盖所有字段类型、条件逻辑、动态填充和属性。
检查器中的位置
将字段放在设置、样式或高级选项卡中。
优先级排序
为多个指定同一区块的扩展排序。
无需渲染回调
HTML标签处理器会自动应用输出。
JSON Schema
专用的 Schema 自动补全和验证。
使用 set 将值映射到HTML
set可使用点号表示法(例如{attributes.fieldId}),将值映射到类、内联样式、数据属性或任何HTML属性。
访问嵌套对象中的值,按条件应用值,或将一个字段输出到多个属性。
字段返回多个值时,会对每个值应用 set。类和样式会累加;对于其他属性,"join": true 会用空格分隔并写入每个值,而不是只保留最后一个。
{
"name": "core/heading",
"blockstudio": {
"extend": { "priority": 10 },
"attributes": [
{
"id": "customColor",
"type": "select",
"returnFormat": "both",
"options": [
{ "value": "#f00", "label": "Red" },
{ "value": "#00f", "label": "Blue" }
],
"set": [
{ "attribute": "style", "value": "color: {attributes.customColor.value}" },
{ "attribute": "data-color", "value": "{attributes.customColor.label}" },
{ "attribute": "class", "value": "has-custom-color" }
]
}
]
}
}{
"name": "core/group",
"blockstudio": {
"extend": true,
"attributes": [
{
"id": "langs",
"type": "checkbox",
"label": "Languages",
"options": [
{ "value": "en", "label": "English" },
{ "value": "de", "label": "German" }
],
"set": [{
"attribute": "data-langs",
"value": "{attributes.langs}",
"join": true
}]
}
]
}
}可指定一个区块,也可指定数千个
指定一个名称(如"core/paragraph")、一组名称,或使用"core/*"指定整个命名空间。
多个JSON扩展可以指定同一个区块。优先级决定它们在检查器中的顺序。
顶层的 exclude 列表会跳过匹配 name 的区块,并使用相同的精确匹配和通配符匹配规则。被排除的区块既不会获得字段,也不会输出字段内容。
{
"name": "core/*",
"blockstudio": {
"extend": { "priority": 10 },
"attributes": [
{
"id": "animation",
"type": "select",
"options": [
{ "value": "fade", "label": "Fade" },
{ "value": "slide", "label": "Slide" }
]
}
]
}
}{
"name": ["core/group", "core/cover"],
"blockstudio": {
"extend": { "priority": 20 },
"attributes": [
{
"id": "visibility",
"type": "select",
"options": [
{ "value": "visible", "label": "Visible" },
{ "value": "hidden-mobile", "label": "Hidden on mobile" }
]
}
]
}
}{
"name": "core/*",
"exclude": ["core/button", "core/image"],
"blockstudio": {
"extend": true,
"attributes": [
{ "id": "reveal", "type": "toggle", "label": "Reveal on scroll" }
]
}
}排除区块
跳过单个区块或整个前缀,避免它们被通配符匹配。
合并值
将多值字段中选定的所有值写入同一个属性。
属性字段
属性字段无需设置规则,即可将名称和值对写入区块。
从 PHP 检查
bs_block_extension_fields() 会返回所有匹配扩展添加到区块的字段,包括核心区块和第三方区块。
官方扩展套件
高级站点模板、AI 系统指令和私人 Discord 社区。一次购买,终身更新。
- 500+ 个网站模板
- AI 系统指令
- 终身更新
- 私有 Discord 社区