What is the naming rule for template variables?(For example:`archive.Id`)

Calendar 👁️ 64

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 ascustom_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 areitem.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.

Related articles

Are conditional judgment and loop control tags in the template required to have closing tags?

As an experienced CMS website operation person, I am well aware of the importance of template design for website content display and user experience.During the process of content creation, editing, and publishing, we often deal with templates, and understanding the correct usage of template tags, especially the closure requirements of conditional judgment and loop control tags, is the basis for ensuring the correct rendering of content and the stable operation of the website.About whether the end tags are required for conditional judgment and loop control tags in the template, the template engine of AnQi CMS follows clear conventions.Make the agreement document according to the template we provide, **condition judgment

2025-11-06

How to distinguish between variable output (`{{ }}`) and logical control tags (`{% %}`) in AnQi CMS template?

As an experienced AnQiCMS website operator, I am well aware of the core role of templates in content presentation and user experience.Mastering AnQiCMS template syntax, especially distinguishing between variable output and logical control tags, is the key to refined operation and achieving personalized content display. ### Data Display and Logic Control in AnQiCMS Template The design of AnQiCMS template aims to provide strong flexibility, allowing content to be displayed in a diverse manner according to business needs. In the template file, we mainly encounter two types of special markers: double curly braces `{{

2025-11-06

Where should the static resources such as images, JS, and CSS used in the template be stored统一放在哪里?

Hello!As an experienced security CMS operator, I fully understand the importance of static resource management in website construction and content management.High-quality static resource management not only improves website performance, but also optimizes maintenance efficiency.According to the Anqi CMS documentation and our practical experience, here is a detailed explanation of where the static resources such as images, JS, and CSS used in the template should be stored.

2025-11-06

Which folder under the website root directory must all template files be stored in?

As an experienced website operator familiar with the operation mechanism of AnQiCMS, I deeply understand that the template structure of a content management system (CMS) is crucial for the display, maintenance, and optimization of a website.A clear and standardized template file storage rule is the foundation for ensuring the efficient operation of the website and the smooth release of content.In the Anqi CMS system, all template files used to build the website front-end interface have their specific storage location.

2025-11-06

What encoding format should the template file be saved in to avoid page garbled characters?

Hello!As an experienced CMS website operation person, I know that every detail in content publishing and website maintenance may affect user experience.The page garbled characters are one of the common and annoying problems, which are directly related to the correct presentation of content.According to the Anqi CMS documentation, there is a clear and simple solution to this problem.

2025-11-06

What types of template modes does Anqi CMS support?

As a website operator who deeply understands the operation of AnQiCMS (AnQiCMS) and has a profound understanding of content operation, I am very happy to give you a detailed explanation of the template mode supported by AnQiCMS.In AnQiCMS design philosophy, flexibility and adaptability are among its core advantages, which naturally also manifest in its powerful template system.AnQiCMS knows that different websites and operational strategies have diverse needs for front-end display.

2025-11-06

How to design a mobile template for independent mobile sites or code adaptation mode?

As a senior content operator specializing in AnQiCMS, I am well aware that in today's mobile internet era, providing users with an excellent mobile experience is the cornerstone of website success.Anqi CMS, with its flexible architecture, provides us with a variety of solutions to meet the challenges of mobile devices.Today, I will elaborate on how to design high-quality mobile templates for independent mobile sites or code adaptation mode in Anqi CMS.

2025-11-06

Where should the mobile template files be stored in a specific subdirectory?

As a senior security CMS website operation personnel, I fully understand the core position of content in user experience, and providing optimized content display for different devices is the key to retaining users.When it comes to the mobile template management of AnQi CMS, specifying the storage location of the template files is crucial for efficient content publishing and maintenance.In AnQi CMS, in order to adapt to the display of mobile devices, the system provides a specific mechanism to manage the template files for the mobile end.

2025-11-06