Hello! As an experienced AnQiCMS website operator, I am very happy to share with you the key knowledge about AnQiCMS template creation.In my daily work, reasonable planning and precise application of templates are the foundation for ensuring efficient content display and enhancing user experience.A deep understanding of the basic conventions and directory structure specifications of AnQiCMS templates not only allows us to create and publish content more smoothly, but also lays a solid foundation for the long-term maintenance and optimization of the website.
Next, I will elaborate on the basic conventions and directory structure specifications followed by AnQiCMS template creation, helping you better master this powerful tool.
Basic conventions for AnQiCMS template creation
Build and customize templates in AnQiCMS, which requires adhering to a series of clear conventions to ensure the system can correctly parse and render your design.These conventions cover a wide range of aspects, including file formats, naming conventions, and template engine syntax.
Firstly, all template files are统一使用.htmlAs file extensions, and centrally stored in the root directory of the website./templateIn the folder. To maintain the purity and ease of management of the template file, the style sheets, JavaScript scripts, and static resources such as images that the template depends on should be stored independently./public/static/The directory, not mixed into the template file directory inside.
On template writing, AnQiCMS adopts syntax similar to Django template engine. This means you will use double curly braces to define and output variables, for example{{变量}}For more complex logic control, such as conditional judgment and loop traversal, use labels enclosed in single curly braces and percent signs, for example{% if 条件 %}These control flow tags usually need to appear in pairs, for example{% if ... %}Need corresponding{% endif %}To end.
Variable naming also has its rules. In the AnQiCMS template, variable names usually follow the camel case naming convention, and the first letter of each word must be capitalized.For example, you will seearchive.Id/archive.TitleVariables in the form of,IdandTitleThis naming convention starts with an uppercase letter. This helps to maintain consistency and readability in the code.
Moreover, the encoding format of the template file is crucial. AnQiCMS requires all template files to use UTF-8 encoding uniformly.If the template file uses a different encoding format, the page may display乱码when displayed, causing the content to be presented abnormally.Therefore, if you are editing template files in a Windows environment, please make sure to select UTF-8 encoding when saving.
AnQiCMS also supports various template types to adapt to different website designs and access needs.This includes adaptive template types, code adaptation template types, as well as independent templates for PC and mobile phones.When you choose the code adaptation mode or the PC + mobile end mode, the system allows you to design a separate template for mobile devices separately.These mobile templates need to be stored in the main template directory.mobileIn the subdirectory, and the internal directory structure and file naming rules are consistent with the PC template.
To further improve the flexibility and convenience of the template, AnQiCMS also supports some default custom template names.This means that as long as you create these template files following a specific naming format, the system can automatically identify and apply them without any additional configuration in the background.For example, the default custom template for the document can be named{模型table}/{文档id}.htmlThe default template for the document list is{模型table}/list-{分类id}.htmlAnd the default template for a single page ispage/{单页面id}.htmlThis mechanism greatly simplifies the process of designing personalized templates for specific content or categories.
AnQiCMS template directory structure specification
Understanding the template directory structure of AnQiCMS is the foundation for efficient management and development of templates. All related template files are stored in the/templateAs the root directory, each independent template needs to have its own exclusive directory under it.
Within a template directory, there is a directory namedconfig.jsonThe configuration file is indispensable. This file carries key information about the template, including the template name, package name, version, description, author, homepage, creation time, template type, and usage status. Althoughconfig.jsonThe fields are mostly optional, but they are crucial for the identification and management of the template. For example,namefields are used to specify the display name of the template,packageThe field represents the folder name of the template, andtemplate_typeIt indicates the responsive behavior of the template (0 for adaptive, 1 for code adaptation, 2 for PC + mobile). It is particularly noteworthy that,statusThe field (0 for disabled, 1 for in use) in an AnQiCMS installation can only have one template set as1which indicates the currently used template.
AnQiCMS offers two main template file organization modes to accommodate different development habits and project scales: folder organization mode and flattened file organization mode.
InFolder organization modeBelow, template files are logically grouped and stored in different subdirectories:
- Public code files, such as the header and footer of a website, are usually named:
bash.htmlfor other pages to inherit and reference. - Reusable code snippets, such as sidebars, breadcrumb navigation, etc., are stored in
partial/In the catalog. - The homepage file of a website is usually
index/index.html. - There will be a model homepage for different content models, for example
{模型table}/index.html. - The document detail page can be
{模型table}/detail.htmlor it can be specific to a document ID{模型table}/detail-{文档ID}.html. - The document list page is similar, it is
{模型table}/list.htmlor it can be specific to a category{模型table}/list-{文档分类ID}.html. - The comment list page is usually
comment/list.html, the online message page isguestbook/index.html. - The single page detail page is
page/detail.htmlor,page/detail-{单页ID}.html. - The search results page, tag page, and error page also have their corresponding default positions, such as
search/index.html/tag/index.html/tag/list.html/errors/404.html/errors/500.htmlas well aserrors/close.html. - As previously mentioned, if the mobile template is enabled, the file structure will be
mobile/repeated in the directory as described above.
AndFlat file organization modeFiles should be placed directly in the template root directory, distinguished by the prefix or suffix of the filename to indicate their function and module. For example, the homepage isindex.html, and the model home page is{模型table}_index.html, the document detail page is{模型table}_detail.htmlThis pattern simplifies the directory hierarchy, but requires filenames to be more explicit and identifiable.
These organizational modes both allow for custom naming of some template files. This means that if you need to apply a unique template to a specific document, category, or single-page application, you can specify a custom template file name in the background settings (for examplepage/about.htmlAs long as the file exists in your template design package, the system can apply it to the corresponding page.This high degree of flexibility ensures that AnQiCMS can meet various personalized content display needs.
Frequently Asked Questions
1. Where can I find the detailed label usage document for AnQiCMS template creation?As an AnQiCMS operation personnel, I know that template tags are the core of content display.All template tags' detailed usage methods and parameter descriptions can be found in the "Template Creation" -> "Tags and Usage" and "Template Tag Invocation" sections of the AnQiCMS official documentation.This includes a comprehensive guide to 38 commonly used tags from system settings to document lists, category details, etc., which can help you efficiently build dynamic content pages.
2. What should I pay attention to when editing template files on Windows to avoid garbled characters?This is a common question. To ensure that your AnQiCMS website can display normally in different environments, the template files must use UTF-8 encoding consistently.When editing on Windows, be sure to save the file in UTF-8 format.Most modern editors (such as VS Code, Sublime Text, Notepad++) support selecting encoding format when saving. Please make sure you have selected the correct option to avoid page garbled text issues.
3. What types of template display modes does AnQiCMS support?AnQiCMS to meet the diverse needs of website requirements, provides three main template display modes: adaptive template type, code adaptation template type, and PC + mobile end template type.You can choose the most suitable model based on the audience and design strategy of the website.Among them, if you choose code adaptation or PC+mobile terminal mode, the system also supports designing and storing templates separately for mobile devices, and these mobile terminal templates should be placed in the main template directory.mobileIn the subdirectory.