---
title: "概述"

doc_type: static
doc_category: static
doc_version: v20270301
source_url:
  html: 'https://developer.shopline.com/zh-hans-cn/docs/online-store-3-0-themes/theme-and-editor-interaction/overview'
  md: 'https://developer.shopline.com/zh-hans-cn/docs/online-store-3-0-themes/theme-and-editor-interaction/overview.md'
---
# 概述

为了让主题设计能适配不同商家的需求，让不了解代码的商家可以通过图形界面自行调整店铺页面的样式，SHOPLINE 提供了主题编辑器让商家可以方便地使用主题中的配置项自行控制店面的样式。例如，商家可以利用主题中轮播图提供的配置项，上传或替换不同营销节日中的轮播图片。

* * *

## schema{#GPCzB}

schema 是定义主题的全局控件配置、组件控件配置和区块控件配置的一套协议，可以供商家在主题编辑器中通过定义的控件来对主题进行设计。

你可以在以下对应的主题文件中添加 schema：

<table>
  <colgroup>
    <col/>
    <col/>
  </colgroup>
  <tbody>
    <tr>
      <th>
        <p>位置</p>
      </th>
      <th>
        <p>描述</p>
      </th>
    </tr>
    <tr>
      <td colSpan="1" rowSpan="1">
        theme.schema.json
      </td>
      <td colSpan="1" rowSpan="1">
        全局控件配置
      </td>
    </tr>
    <tr>
      <td colSpan="1" rowSpan="1">
        sections 目录下的组件文件
      </td>
      <td colSpan="1" rowSpan="1">
        组件控件配置
      </td>
    </tr>
    <tr>
      <td colSpan="1" rowSpan="1">
        blocks 目录下的区块文件
      </td>
      <td colSpan="1" rowSpan="1">
        区块控件配置
      </td>
    </tr>
  </tbody>
</table>

* * *

## JSON 配置数据{#ucby6}

JSON 配置数据是指商家通过主题编辑器控件配置的数据。这些配置的数据将会以 JSON 的形式存储在以下两个地方：

-   **theme.config.json**：存储全局控件配置的数据
    
-   **templates/\*.json**：存储组件和区块控件配置的数据。具体存储的模板文件，取决于组件被添加到哪一个页面中。
    

* * *

## 访问配置项的值{#s9PW8}
定义好 schema 后，如果要在 HTML 代码中访问不同类型的配置值，你需要使用不同的 Sline 对象。
<table>
  <colgroup>
    <col/>
    <col/>
    <col/>
  </colgroup>
  <tbody>
    <tr>
      <th>
        <p><strong>配置类型</strong></p>
      </th>
      <th>
        <p><strong>使用对象</strong></p>
      </th>
      <th>
        <p><strong>访问方式</strong></p>
      </th>
    </tr>
    <tr>
      <td colSpan="1" rowSpan="1">
        全局控件配置
      </td>
      <td colSpan="1" rowSpan="1">
      settings 
      </td>
      <td colSpan="1" rowSpan="1">
        settings.\{具体配置项的 id 值\}
      </td>
    </tr>
    <tr>
      <td colSpan="1" rowSpan="1">
        组件控件配置
      </td>
      <td colSpan="1" rowSpan="1">
        section.settings
      </td>
      <td colSpan="1" rowSpan="1">
        section.settings.\{具体配置项的 id 值\}
      </td>
    </tr>
    <tr>
      <td colSpan="1" rowSpan="1">
        区块控件配置
      </td>
      <td colSpan="1" rowSpan="1">
        block.settings
      </td>
      <td colSpan="1" rowSpan="1">
        block.settings.\{具体配置项的 id 值\}
      </td>
    </tr>
  </tbody>
</table>

你可以参考如下说明查看该如何访问不同配置项的值。
### 访问全局配置项的值{#cEJpL}

全局配置项只能在 theme.schema.json 文件中定义。

例如在 theme.schema.json 中定义以下 schema：

```shell
{
  ...
  schemas: [
    {
      "name": "Theme Title",
      "settings": [
        {
          "type": "text",
          "id": "title",
          "label": "Title",
          "default": "My Theme Title"
        }
      ]
    }
  ]
}
```

然后可以在任意的 `.html` 文件中通过 [settings](https://developer.shopline.com/zh-hans-cn/docs/sline/object/settings.md) object 方式进行访问，例如：

```html
<!-- layout/theme.html -->

<!DOCTYPE html>
<html>
  <head>
    ...
  </head>
  <body>
    ...
    <div>{{ settings.title }}</div>
    ...
  </body>
</html>

```

输出：

```html
<!-- layout/theme.html -->

<!DOCTYPE html>
<html>
  <head>
    ...
  </head>
  <body>
    ...
    <div>My Theme Title</div>
    ...
  </body>
</html>
```

### 访问组件配置项的值{#DZKu1}

组件配置项只能在组件的 `.html` 文件中定义。

例如在组件中的 [schema](https://developer.shopline.com/zh-hans-cn/docs/sline/tag/schema.md) tag 中定义以下 schema：

```html
{{#schema}}
{
  "name": "Blog",
  "settings": [
    {
      "type": "text",
      "id": "title",
      "label": "Blog title",
      "default": "My Blog Title"
    }
  ]
}
{{/schema}}
```

然后可以在组件中的 `.html` 文件中通过 [section.settings](https://developer.shopline.com/zh-hans-cn/docs/sline/object/section.md) object 进行访问，例如：

```html
<!-- sections/blog/blog.html -->

<div>
  {{ section.settings.title }}
</div>

{{#schema}}
{
  "name": "Blog",
  "settings": [
    {
      "type": "text",
      "id": "title",
      "label": "Blog title",
      "default": "My Blog Title"
    }
  ]
}
{{/schema}}
```

输出：

```html
<!-- sections/blog/blog.html -->

<div>
  My Blog Title
</div>

{{#schema}}
{
  "name": "Blog",
  "settings": [
    {
      "type": "text",
      "id": "title",
      "label": "Blog title",
      "default": "My Blog Title"
    }
  ]
}
{{/schema}}
```

> **注意**
>
> [section](https://developer.shopline.com/zh-hans-cn/docs/sline/object/section.md) object 只能在组件文件中访问。

### 访问区块配置项的值{#Yowwm}

区块配置项只能在区块的 `.html` 文件中定义。

例如在区块中的 [schema](https://developer.shopline.com/zh-hans-cn/docs/sline/tag/schema.md) tag 进行定义：

```html
<!-- blocks/button.html -->

{{#schema}}
{
  "name": "Button",
  "settings": [
    {
      "type": "text",
      "id": "text",
      "label": "Button",
      "default": "confirm"
    }
  ]
}
{{/schema}}
```

然后可以在区块中的 `.html` 文件中通过 [block.settings](https://developer.shopline.com/zh-hans-cn/docs/sline/object/block.md) object 进行访问，例如：

```html
<!-- blocks/button.html -->

<button>{{ block.settings.text }}</button>

{{#schema}}
{
  "name": "Button",
  "settings": [
    {
      "type": "text",
      "id": "text",
      "label": "Button",
      "default": "confirm"
    }
  ]
}
{{/schema}}
```

输出：

```html
<!-- blocks/button.html -->

<button>confirm</button>

{{#schema}}
{
  "name": "Button",
  "settings": [
    {
      "type": "text",
      "id": "text",
      "label": "Button",
      "default": "confirm"
    }
  ]
}
{{/schema}}
```
:::warning{title="注意"}
[block](https://developer.shopline.com/zh-hans-cn/docs/sline/object/block.md) object 只能在区块文件中访问。