As an experienced website operations expert, I know the importance of a flexible content management system for personalized website display.AnQiCMS (AnQiCMS) performs very well in this aspect, allowing us to set independent display templates for specific content, which undoubtedly provides us with great freedom in content marketing and user experience optimization.Where should the custom template file be placed when we want to design a unique display style for a specific document (such as an article, a special product page, or a special single page)?Today, let's delve deeply into this issue.
The foundation of AnQi CMS template files:/templateTable of contents
Firstly, we need to clarify the template files of Anqi CMSroot directory.No matter which theme template you use, they are all stored in the Anqi CMS installation directory./templateIn the folder. In this/templateDirectory, you will see one or more subfolders named with topic names, such asdefault. Any custom template files you create should be placed inThe currently enabled theme template folderwithin. For example, if your theme name ismythemethen your custom template file will finally exist in/template/mytheme/the directory or its subdirectories.
The location and naming of custom template files under the two main scenarios
AnQi CMS provides two main mechanisms to specify display templates for specific documents, these two mechanisms determine how your custom template files should be named and placed:
Scenario one: Intelligent recognition based on content ID or alias
AnQi CMS has a "agreement first" intelligent recognition mechanism.This means that if you place template files according to specific naming conventions, the system can automatically match and apply these templates to the corresponding documents without any additional settings in the background.
ID matching for general documents (such as articles, products):When you need to set an independent template for a document with a specific ID (for example, an article or product with ID 123), you can name the template file:
{模型table}/{文档id}.htmlFor example, if your article model corresponds to the table namedarticleand you want to create an independent template for the article with ID123then you can name the file asarticle/123.htmlplace it in the root directory of the current theme template (i.e.),/template/mytheme/article/123.htmlThe system will automatically load this exclusive template when accessing this article with ID 123.For matching ID or alias on a single page:A single page is a common special content type on a website, such as "About Us
page/{单页面id}.htmlorpage/{单页面别名}.htmlFor example, if you have a page with an ID of15, the template file can be namedpage/15.html. If you have set a custom URL alias for the "About Us" page in the background,about-usThen you can create a file namedpage/about-us.htmltemplate file. When the system accesses the single page, it will first search and apply this specific template.
The advantage of this intelligent recognition is that once the file is in place, the system can automatically associate and simplify the background configuration process.
Scenario two: Flexibly specify through the background "document template" field.
In addition to intelligent recognition, Anqi CMS also provides a more flexible way, allowing you to manually specify a custom template on the document editing page.This method is applicable when the template file name does not follow the ID or alias naming rules, or when you want to apply the same template to multiple different ID documents.
When editing a document (article, product, page), you will find a named parameter in the "Other Parameters" or "Advanced Settings".Document TemplateThe field (the specific name may vary slightly depending on the version of Anqicms, but it refers to the same thing).Here, you can directly fill in the path and filename of the custom template file relative to the root directory of the current theme template.
- Location of the template file: Your custom template file still needs to be placed in the template folder of the current theme
/template/mytheme/Inside. - Example of template file name:
- If you place the file directly in the root directory of the theme template (for example
/template/mytheme/download.html), then you just need to fill in the "Document Template" fielddownload.html. - If you have created subdirectories (for example, to organize templates
/template/mytheme/custom/product-offer.html), then you need to fill in the "Document Template" fieldcustom/product-offer.html.
- If you place the file directly in the root directory of the theme template (for example
The flexibility of this method lies in the fact that you can create a universal template for a set of documents that have common display requirements (such aspromotion-detail.html), then just specify the template file in the background of each relevant document.
Actual Operation Suggestions and **Practice
- Unified theme folder:Always place all your custom template files in the current active theme template folder. Do not directly modify the Anqie CMS core.
/templateThe directory or default theme, as this may cause the file to be overwritten after update. - Clear directory structure:In order to facilitate management and maintenance, I strongly recommend that you create a logically clear subdirectory within the theme template folder. For example:
article/: Stores all templates related to articles.product/: Store all product-related templatespage/: Store all single-page related templatespartial/: Store reusable code snippets, such as headers, footers, and sidebarscustom/: Store those general custom templates that do not belong to a specific model but need to be manually specified
- Use
.htmlExtension name:Anqi CMS template files are unified in use.htmlAs the file extension. - UTF-8 Encoding:Ensure all template files are saved in UTF-8 encoding to avoid Chinese garbled text issues.
- Precision of background fields:If you choose to manually specify the template through the background field, please make sure that the path and filename you enter match the actual file exactly, including case and file extension, otherwise the system will not be able to find the corresponding template.
- Test is for the king:Always test the document page on the front end after creating or modifying a custom template and associating it with a specific document to ensure the display effect meets expectations.
By using these flexible template specifications and organization methods provided by Anqi CMS, you can easily create unique and engaging display effects for any content on your website, thereby better serving your website operation goals.
Frequently Asked Questions (FAQ)
- Q: If I set a template based on ID for the same document (such as
article/123.html), and also specify another template in the background "Document Template" field (such ascustom/special-article.htmlWhich one will AnQi CMS use first?A: The template loading logic of Anqi CMS usually prioritizes clearer, more specific settings. In this case, the manually specified template in the background "Document Template" field (custom/special-article.htmlThe priority of templates recognized based on ID will be higher than those automatically identified based on IDarticle/123.htmlThis means that if you specify it in the background,