# 主题 section 概述

> Shoplazza 主题的 section 如何工作：带 block 的可复用 Liquid 模块，可通过 Liquid template 动态添加，也可静态嵌入页面。

Section 是 Liquid 文件，可让您创建商家可自定义的可复用内容模块。Section 还可以包含 [block](/zh-CN/docs/theme/architecture/sections/section-schema#blocks)，允许商家在 section 内添加、删除和重新排列内容。

例如，您可以创建一个**图文并排**的 section，并排显示图片和文字，同时为商家提供选择图片、设置文字和调整展示顺序的选项。

Section 可以通过 [Liquid template](/zh-CN/docs/theme/architecture/templates/liquid-templates) 动态添加到页面，为商家提供灵活定制页面布局的能力。包含在 Liquid template 中的 section 可以支持 [app block](/zh-CN/docs/theme/architecture/sections/app-blocks-for-themes)，让商家无需编辑 theme 代码即可将应用内容嵌入 section。

Section 也可以[静态嵌入](/zh-CN/docs/theme/architecture/sections/overview#%E9%9D%99%E6%80%81%E6%B8%B2%E6%9F%93-section)，为静态内容提供上下文内联的自定义选项。

默认情况下，section 适用于所有 template。您可以在 [section schema](/zh-CN/docs/theme/architecture/sections/section-schema#%E5%86%85%E5%AE%B9) 中限制可访问的 template 范围。

下图展示了 theme 主要架构组件，其中蓝色高亮为 section，红色高亮为 block：

![](https://cnres.appracle.com/ff1dceaff3ceed661f68904b40429609.png)

## 位置

Section 文件位于 theme 的 `sections` 目录下：

**目录**

```text
└── theme
    ...
    ├── templates
    ├── sections
    ...
```

## 内容

Section 可以包含三种主要内容类型：

| 类型 | 描述 | 是否必填 |
| --- | --- | --- |
| **主内容** | 您希望在 section 中包含的任何 HTML 或 Liquid 内容。<br>Section 与其他 Liquid theme 文件一样，可以访问 [全局对象](/zh-CN/docs/theme/references/liquid/objects/)、[tag](/zh-CN/docs/theme/references/liquid/tags/) 和 [filter](/zh-CN/docs/theme/references/liquid/filters/)，以及以下 section 特有对象：<br>*   [section 对象](/zh-CN/docs/theme/references/liquid/objects/sections) - 包含 section 的属性和设置值。<br>*   [block 对象](/zh-CN/docs/theme/references/liquid/objects/blocks) - 包含单个 section block 的属性和设置值。<br>除全局对象外，在 section 外部创建的变量在 section 内部无法访问。<br>section 和 block 对象，以及在 section 内部创建的变量，在其所属 section 之外不可用。唯一的例外是当您在该 section 内部渲染的 snippet 中引用这些 section 和 block 对象时。 | 否 |
| **资源** | Section 可以使用以下 section 专用 Liquid tag 打包自己的 JavaScript 和样式表资源：<br>*   [{% javascript %}](/zh-CN/docs/theme/references/liquid/tags/theme-tags#javascript)<br>*   [{% stylesheet %}](/zh-CN/docs/theme/references/liquid/tags/theme-tags#stylesheet)<br>更多信息请参考 [Section 资源](./section-assets)。 | 否 |
| **Schema** | Section 支持 section 专用的 `{% schema %}` Liquid tag。该 tag 用于定义以下 section 属性和设置：<br>*   [name](./section-schema#name)<br>*   [templates](./section-schema#templates)<br>*   [class](./section-schema#class)<br>*   [limit](./section-schema#limit)<br>*   [settings](./section-schema#settings)<br>*   [blocks](./section-schema#blocks)<br>*   [app block](./app-blocks-for-themes)<br>*   [max_blocks](./section-schema#max_blocks)<br>*   [presets](./section-schema#presets)<br>更多信息请参考 [Section schema](./section-schema)。 | 是 |

## 使用说明

使用 section 时，您应该熟悉以下内容：

*   [如何渲染 section](/zh-CN/docs/theme/architecture/sections/overview#%E6%B8%B2%E6%9F%93-section)
*   [支持 app block](/zh-CN/docs/theme/architecture/sections/overview#%E6%94%AF%E6%8C%81-app-block)

### 渲染 section

您可以通过以下方式之一渲染 section：

*   在 [Liquid template](/zh-CN/docs/theme/architecture/templates/liquid-templates) 中引用 section。
*   使用 `section` Liquid tag [静态渲染](/zh-CN/docs/theme/architecture/sections/overview#%E9%9D%99%E6%80%81%E6%B8%B2%E6%9F%93-section) section。

#### 静态渲染 section

您可以使用 Liquid [section tag](/zh-CN/docs/theme/references/liquid/tags/theme-tags#section) 静态渲染 section。

例如，要在 Liquid layout 中包含某个 section，可以使用 section tag：

**layout/theme.liquid**

```liquid
<body>
  ...
  {% section 'header' %}
  ...
</body>
```

### 支持 app block

App block 允许应用开发者创建 block，让商家无需直接编辑 theme 代码即可将应用内容添加到 theme 中。

了解如何使您的 theme 与 app block 兼容，请参考 [App block](/zh-CN/docs/theme/architecture/sections/app-blocks-for-themes)。
