# Daiying CMS V1.2 主题开发规范
版本:2026-08-31
适用版本:Daiying CMS V1.2
## 1. 基本原则
主题只负责前台展示:HTML、CSS、响应式、模板结构、少量前台交互和主题设置读取。主题不得修改业务数据,不得实现支付、库存、订单、授权、发卡、云存储等功能规则。
主题不得修改 `system/core`、`config`、`storage`、`public/index.php`,不得要求站长手动改 Core。
## 2. 主题目录
主题安装目录:
```text
content/themes/{theme_id}/
```
最小结构:
```text
content/themes/mytheme/
theme.json
templates/
home.php
list.php
content.php
error.php
assets/
```
`theme_id` 必须与目录名一致。
## 3. theme.json
```json
{
"theme_id": "mytheme",
"name": "My Theme",
"version": "1.0.0",
"author": "Your Name",
"core": {"min": "1.2.3", "max": "1.x"},
"content_types": ["article", "page"],
"recommended_plugins": [],
"required_plugins": [],
"settings_schema": {}
}
```
`theme_id` 规则:
- 小写字母开头。
- 只允许小写字母、数字、下划线。
- 长度 3 到 64。
- 禁止使用 `safe`。
## 4. settings_schema
推荐字段类型:
```text
text
textarea
url
email
color
toggle
range
image
```
常用属性:
| 属性 | 说明 |
| --- | --- |
| `type` | 字段类型 |
| `label` | 后台显示名 |
| `group` | 后台分组 |
| `order` | 排序 |
| `default` | 默认值 |
| `placeholder` | 占位提示 |
| `min` / `max` / `step` | 数值约束 |
图片字段要求:
- 如果主题自带官方 Logo,应默认使用主题资源,不应强迫用户填写 URL。
- `image` 设置保存值可能是字符串 URL,也可能是媒体对象。
- 主题读取时应兼容 `/uploads/...`、`uploads/...`、`content/uploads/...`、`http://...`、`https://...`。
- 输出前必须过滤 URL,禁止 `javascript:`、控制字符、引号和 HTML 注入。
## 5. 模板
推荐模板:
| 模板 | 用途 |
| --- | --- |
| `home.php` | 首页 |
| `list.php` | 列表页 |
| `content.php` | 文章和页面详情 |
| `error.php` | 404 或错误页 |
| `_theme.php` | 公共函数,可选 |
模板头部:
```php
get('title', '');
$context->setting('primary_color', '#1f6feb');
$context->e($value);
```
所有不可信文本必须使用 `$context->e()` 输出。
## 7. 内容上下文
`home.php` 常用:
| Key | 说明 |
| --- | --- |
| `site_name` | 站点名称 |
| `navigation` | 导航数组 |
| `contents` | 最新内容列表 |
| `seo` | SEO 数据 |
`list.php` 常用:
| Key | 说明 |
| --- | --- |
| `title` | 列表标题 |
| `items` | 内容列表 |
| `pagination` | 分页数据 |
| `term` | 分类或标签 |
| `empty_message` | 空列表提示 |
`content.php` 常用:
| Key | 说明 |
| --- | --- |
| `content` | 内容原始数据 |
| `title` | 标题 |
| `media` | 媒体 ViewModel |
| `rendered_blocks` | 已渲染区块 HTML |
| `paid_content` | 付费内容状态 |
| `categories` | 分类 |
| `tags` | 标签 |
| `comments` | 评论数据 |
内容正文推荐:
```php