Basic conventions and file directory structure requirements for AnQi CMS template creation
In Anqi CMS, template creation requires adherence to a series of basic conventions to ensure compatibility, maintainability, and efficient operation.These conventions cover file naming, encoding, syntax, and static resource management, etc.
Anqi CMS template files are unified in use.htmlAs a file suffix, and stored centrally in the system/templateIn the directory.In order to avoid garbled characters on the page, all template files must use UTF-8 encoding format.For Windows users, when editing template files, it is necessary to save the file in UTF-8 encoding.
The syntax of the template engine is similar to the Django template engine, so developers familiar with similar syntaxes like Blade will find it very easy to get started. In the template, variable definitions use double curly braces, for example{{变量名}}However, logical tags such as condition judgment and loop control are defined using single curly braces and percent signs, for example{% if 条件 %}这是条件为真的内容{% endif %}.It should be noted that these logical tags are usually paired and need corresponding end tags.{archive.Id}or{archive.Title}Of course, there are also some special regulations that are exceptions.
The style sheets (CSS), JavaScript scripts, and images, etc., used in the template should be stored independently./public/static/Under the directory, separated from the template file, to keep the project structure clear and easy to manage.
AnQi CMS supports various template types, including adaptive templates, code adaptation templates, and PC + mobile independent site mode. To better adapt to mobile device access, if code adaptation mode or PC + mobile independent site mode is selected, a template named must be created in the template directory.mobileThe subdirectory is used to store dedicated template files for mobile devices, and its internal directory structure and template file naming are consistent with the PC template.
In template creation, Anqi CMS also supports some default custom template names. As long as the template files with these specific names exist, the system can automatically apply them without any additional settings in the background. For example, the default custom template name format for documents is{模型table}/{文档id}.htmlThe default custom template name format for the document list is{模型table}/list-{分类id}.htmlAnd the default custom template name format for the single page ispage/{单页面id}.html.
The file directory structure requirements for the template
The template root directory of Anqi CMS is/template. Each independent template must create its own dedicated directory under this root directory and include aconfig.jsonConfiguration file. This configuration file is the identity identifier of the template, which informs the system of all the basic information of the template.
config.jsonThe content of the file is as follows, all fields are optional, and if not filled in, the system will generate default values according to the actual situation:
{
"name": "默认模板",
"package": "default",
"version": "1.0",
"description": "系统默认模板",
"author": "kandaoni.com",
"homepage": "https://www.kandaoni.com",
"created": "2022-05-10 22:29:00",
"template_type": 0,
"status": 0,
}
The field descriptions include:name(The name of the template),package(Template folder name, only supports letters and numbers),version(Template version),description(Template description),author(Template author),homepage(Author's website),created(Creation time),template_type(Template type, 0 for adaptive, 1 for code adaptation, 2 for computer + mobile mode), as well asstatus(Template usage status, 0 for disabled, 1 for in use). It must be emphasized that in all templates, only one set of templates can be used.statusThe value is set to 1, meaning only one template can be enabled at a time.
On the organization of template files, Anqi CMS provides two main modes: folder organization mode and flattened file organization mode.
Folder organization mode
In this mode, template files are organized into different subdirectories according to their functions.
bash.html: Usually stores common code snippets such as headers and footers for inheritance and reference by other pages.partial/This is used to store reusable code snippets for sidebars, breadcrumbs, and so on.index/index.htmlThis is the home page template of the website.{模型table}/index.htmlThis is the home page of a specific content model.{模型table}/detail.htmlThis is a general document detail page, or{模型table}/detail-{文档ID}.htmlCustom detail page for specific document.{模型table}/list.html: General document list page, or{模型table}/list-{文档分类ID}.htmlCustom list page for specific category.comment/list.html: Comment list page.guestbook/index.html: Online message page.page/detail.html: General single-page detail page, orpage/detail-{单页ID}.htmlCustom detail page for a specific single page.search/index.html: Search results page.tag/index.html: Tag homepage.tag/list.html: Tag document list page.errors/404.html: 404 error page.errors/500.html: 500 error page.errors/close.html: Site closed notification page.mobile/If mobile template is enabled, this directory will store mobile template files consistent with the above structure.
Flat file organization mode
This