As a senior CMS website operations personnel for an information security company, I know that a clear and consistent naming convention for template variables is crucial for the efficient operation and content management of the website.This not only improves the efficiency of template development and maintenance, but also helps operation personnel quickly locate and understand the data structure when adjusting content.In AnQi CMS, the naming of template variables follows a clear convention, aimed at ensuring the readability and maintainability of the system.

In the template system of AnQi CMS, data variable access is mainly through double curly bracket syntax{{变量名}}Implementation. When we need to access a specific property of an object, Aiqi CMS uses the dot notation (" to connect the object and its property, forming.) to connect the object and its property, forming{{对象.属性名}}such a structure.

The template variable naming of AnQi CMS, especially for the built-in core data models (such as documents, categories, pages, etc.) properties, generally followscamel case naming conventionsThis means that the first letter of each word in the variable name will be capitalized, for examplearchive.Id/archive.Title/category.Link/pages.CurrentPageThis naming convention makes the meaning of the variable clear and easy to distinguish, for examplearchive.IdThe value directly represents the unique identifier of the current document, whereascategory.Titlerefers to the title of the current category. This consistency is reflected throughout the system, whether it is to obtain the document'sViews(Views), or obtain the category'sDescription(Description), both maintain the same naming style.

Of course, in the actual template development, there are also some flexible naming situations. For example, when iterating through list data in a loop, we usually define each loop item as a short variable name, likeitemorarchiveIn this case, although the loop variable itself is lowercase, the properties it contains still follow camelCase naming conventions, likeitem.Titleorarchive.Link. In addition, when usingwithorsetWhen declaring temporary variables within a template, operators can name them according to actual needs, but it is also recommended to use camelCase or other easily understandable conventions to maintain a consistent style.

When a template tag needs to output a specific field, for example,{% archiveDetail archiveId with name="Id" %},“ here is thearchiveIda custom variable name we define, which will carryIdthe value of the property. Although here,archiveIdCan be named flexibly according to the developer's habit, but thename="Id"parameters in,IdIt is still the system built-in property name following the camel case naming convention.This distinction allows template developers to maintain consistency in the naming of core data structures while assigning more descriptive names to local variables based on their specific scenarios.

In summary, the naming convention of template variables in Anqi CMS is characterized by its clear structure and uniform camel case naming principle, which greatly reduces the cost of understanding and maintaining templates.For content operation personnel, understanding and following these rules can enable more efficient content creation, editing, publishing, and optimization, thereby attracting and retaining users better.


Common Questions and Answers (FAQ)

  • Why do the template variable names of AnQiCMS look more like code variable names rather than natural language?Answer: AnQi CMS is developed in Go language, the coding conventions of Go language and many modern content management system template engines tend to adopt this similar coding variable naming style (such as camelCase).The advantage of this method lies in its clarity and consistency, which can effectively reduce ambiguity, making the template structure clearer. Especially for scenarios that require handling complex data structures or secondary development, this naming rule can greatly improve efficiency and reduce errors.

  • Question: What will be the template variable name if I customize the content model field?Answer: When you customize content model fields, you set the 'calling field' name (usually in lowercase English letters, for example)custom_authororproductPrice)will be used by CMS for template variables. The system will automatically convert it to camelCase format. For example, if you set the calling field isproduct_weightSo when accessing it in the template, it may bearchive.ProductWeight. Therefore, it is recommended to also consider its readability when converting to camel case in the template.

  • Question: I see some variables areitem.Title, some arearchive.Title, what are the differences between them?Answer: This mainly depends on the context in which the variable is used.item.TitleofitemIt is usually a general name, used inforIterating over a list (for example)archiveListorcategoryListthe elements. Andarchive.Titleofarchiverefers more specifically to the main document object of the current page, especially on the document detail pagearchiveDetailIn [en]. Although they all represent 'title',itemis a temporary and general-purpose loop variable, whereasarchiveis usually the main content object of the current page.