开发说明:
主题结构
templates/themes/
└── 主题目录名/
├── int.py # DjacoreCMS 应用包必用
├── theme.jpg # 主题预览图
├── static # 静态文件
├── templates # 模板文件
├── templatetags # 主题预览图
├── themeconfig.json # 主题元信息文件
└── themesettings.json # 个性设置文件themeconfig.json
自0.2.5版本后我们移除了对themeconfig.ini的使用,改为使用themeconfig.json使用
现在themeconfig.json文件如下:
{
"name": "默认主题",
"author": "djacore CMS官方",
"version": "1.0.0",
"description": "系统默认主题样式,推荐非标签数据单表在30万左右以下使用。本主题具备容灾作用,此主题会不定时更新,修改请尽量不要在这个主题修改,可复制后修改使用。",
"main": "这里为具体说明,支持html"
}main这里是支持html的,但是JSON格式有要求,我们需要将“"”替换为“\"”,并且压缩到一行当中。
themesettings.json
我们还在0.2.5版本后加入了themesettings.json的使用,这样在主题管理中我们可以使用主题相关的个性设置
themesettings.json
{
"settings": [
{
"name": "primarycolor",
"label": "主色调",
"type": "color",
"default": "#007bff",
"description": "网站的主要颜色,用于按钮、链接等",
"required": true,
"maxlength": 7
},
{
"name": "backgroundimage",
"label": "背景图片",
"type": "image",
"default": "",
"description": "上传或输入图片URL",
"required": false
},
{
"name": "fontfamily",
"label": "字体家族",
"type": "select",
"options": [
{"value": "Arial, sans-serif", "label": "Arial"},
{"value": "'Microsoft YaHei', sans-serif", "label": "微软雅黑"},
{"value": "'SimSun', serif", "label": "宋体"}
],
"default": "Arial, sans-serif",
"description": "网站默认字体",
"required": true
},
{
"name": "showbreadcrumb",
"label": "显示面包屑导航",
"type": "checkbox",
"default": true,
"description": "是否显示页面面包屑导航"
},
{
"name": "maxposts",
"label": "每页文章数",
"type": "number",
"default": 20,
"min": 1,
"max": 50,
"step": 1,
"description": "列表页每页显示的文章数量",
"required": true
},
{
"name": "sitedescription",
"label": "网站描述",
"type": "text",
"default": "",
"description": "网站的简短描述,用于SEO",
"required": false,
"maxlength": 255
},
{
"name": "siteemail",
"label": "管理员邮箱",
"type": "email",
"default": "admin@example.com",
"description": "网站管理员的联系邮箱",
"required": true
},
{
"name": "siteurl",
"label": "网站URL",
"type": "url",
"default": "https://example.com",
"description": "网站的完整URL",
"required": true
},
{
"name": "publishdate",
"label": "发布日期",
"type": "date",
"default": "2023-01-01",
"description": "内容发布日期",
"required": false
},
{
"name": "enablecomments",
"label": "启用评论",
"type": "boolean",
"default": true,
"description": "是否启用评论功能"
},
{
"name": "contenttype",
"label": "内容类型",
"type": "radio",
"options": [
{"value": "blog", "label": "博客文章"},
{"value": "news", "label": "新闻资讯"},
{"value": "tutorial", "label": "教程指南"}
],
"default": "blog",
"description": "选择内容类型"
},
{
"name": "tags",
"label": "内容标签",
"type": "multiple",
"options": [
{"value": "tech", "label": "技术"},
{"value": "design", "label": "设计"},
{"value": "business", "label": "商业"}
],
"default": ["tech"],
"description": "选择相关内容标签(可多选)"
},
{
"name": "priority",
"label": "优先级",
"type": "range",
"default": 5,
"min": 1,
"max": 10,
"step": 1,
"description": "设置内容优先级(1-10)"
}
]
}表单字段与 JSON 类型对应关系
在模板开发时themesettings.json是可以为空或者是无的,并不是必要项。
我们更建议如果不需要主题个性设置则不放入themesettings.json
themesettings.json中个性变量的使用方法
以theme<json.keyname>为键在模板中直接引用
如上面的安全中的themesettings.json中的"name": "primarycolor",我们在使用的时候可以直接在模板中使用{{themeprimary_color}}来引入个性设置。