As an experienced CMS website operation personnel of an enterprise, I know that a clear and consistent naming rule of 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 set of clear conventions, aimed at ensuring the readability and maintainability of the system.
In the AnQi CMS template system, data variables are accessed mainly through double brace syntax{{变量名}}Implementation. When we need to access a specific property of an object, Anqi CMS uses the dot notation (.) to connect the object and its property, forming{{对象.属性名}}such a structure.
The template variable naming of AnQi CMS, especially for built-in core data models (such as documents, categories, pages, etc.), generally followscamel case naming conventionThis 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.IdDirectly represents the unique identifier of the current document, whilecategory.Titlethen refers to the title of the current category. This consistency is reflected throughout the system, whether it is to obtain the document'sViews(Page views), or get the category'sDescription(Description), all maintain the same naming style.
Of course, in practical template development, there are also some flexible naming situations. For example, when iterating over list data in a loop, we usually define each loop item as a short variable name, such asitemorarchiveIn this case, although the loop variable itself is lowercase, the properties it contains still follow camelCase naming conventions, such asitem.Titleorarchive.Link. Moreover, when usingwithorsetWhen declaring temporary variables within a template, operation personnel can name them according to actual needs, but it is also recommended to use camelCase naming or other easily understandable specifications to maintain a consistent style.
When a template tag needs to output a specific field, for example{% archiveDetail archiveId with name="Id" %}.archiveIdit is a custom variable name that will carryIdthe value of the property. Although here thearchiveIdCan be named flexibly according to the developer's habits, but the referencedname="Id"In the parametersIdIt is still the system built-in attribute 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 according to their own scenarios.
In summary, the naming rules of Anqi CMS template variables, with their clear structure and unified camel case naming convention, greatly reduce 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 better attracting and retaining users.
Frequently Asked Questions (FAQ)
Ask: Why do the template variable names of AnQiCMS look more like code variable names than natural language?Answer: Anqi CMS is developed based on Go language, the programming specifications of Go language, and many modern content management system template engines tend to adopt this variable naming method similar to code (such as camel case).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.
Ask: What will be the template variable name if I customize the content model field?Answer: When you customize the content model field, you set the "call field" name for the field in the background (usually in English lowercase letters, such as
custom_authororproductPrice)Will be used by the Anqie CMS for template variables. The system will automatically convert it to camel case format. For example, if you set the calling field toproduct_weightSo when accessing it in the template, it may bearchive.ProductWeightTherefore, it is recommended to also consider the readability when setting the call field in the template.Ask: I see some variables are
item.Titleand some arearchive.TitleWhat are the differences?Answer: This mainly depends on the context of the variable.item.TitleofitemIt is usually a general name, used toforIterating over a list (for examplearchiveListorcategoryList). And each element at that time.archive.TitleofarchiveIt more specifically refers to the main document object on the current page, especially on the document detail page (archiveDetailIn it. Although they all represent 'title', butitemis a temporary and general-purpose loop variable, whilearchiveis usually the main content object of the current page.