What do `{{item.Title}}` and `{{archive.Title}}` represent in different template contexts?

Calendar 👁️ 79

As an experienced website operations expert, I know that understanding the meaning and usage scenarios of template variables is crucial for efficient website operation in a content management system.AnQiCMS (AnQiCMS) offers a flexible and powerful template engine, providing great convenience for content display.{{item.Title}}and{{archive.Title}}These two seemingly similar variables cause confusion.Today, we will delve into the meanings, usage contexts, and how to skillfully use them to build dynamic and accurate content displays.

The foundation of the Anqi CMS template engine

Before delving deeper into these two variables, let's briefly review the template mechanism of AnQi CMS. The template syntax of AnQi CMS is similar to Django, which uses double curly braces{{ 变量 }}Output a variable value, using single curly braces plus percent sign{% 标签 %}To handle logic control, for example, loops (for), conditional judgments (if)et al. This design makes the template structure clear, easy to understand and maintain. It is worth mentioning that according to the update log of AnqiCMS,archiveThe tag is inv2.1.1version has replaced the originalarticle/producttag, which indicatesarchiveIt has become the core concept representing 'document' or 'content item' in the system.

{{item.Title}}: Each shining star in the list

When you need to display a series of contents on a website, such as a list of blog articles, product categories, friend links, or sidebar recommendations,{{item.Title}}it will become your powerful assistant.

itemVariables usually appear in the template'sloop (for) structureinside. It represents the single content item in the current loop iteration of.Imagine you are usingarchiveListtags to get the latest list of articles:

{% archiveList latestArticles with type="list" limit="5" %}
    {% for item in latestArticles %}
        <div class="article-preview">
            <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
            <p>{{ item.Description|truncatechars:100 }}</p>
            <span>发布于 {{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
        </div>
    {% endfor %}
{% endarchiveList %}

In this example,latestArticlesis a collection of article lists. Whenforyou iterate through this collection in a loop, each iteration will take the currentArticle objectAssign toitemVariable. Therefore,{{item.Title}}It will dynamically output the title of the article reached by the current loop,{{item.Link}}Then output its link,{{item.Description}}Output its description.

Not limited toarchiveList, other tags used to obtain list data, such ascategoryList(Category list),tagList(Tag list),pageList(Single page list) andnavList(Navigation list) and theirforwill be used inside the loopitemrepresents each independent list element. It acts as a temporary container, carrying the complete information of the current element at every moment of the loop.

{{archive.Title}}: Identity identification of the core content of the page.

withitem.TitleThe dynamic, iterative characteristics are different,{{archive.Title}}Carrying a more core and unique responsibility - it represents the currentThe main content (document) carried by the pageTitle.

This variable is mainly used inDocument detail page(For example, accessingarticle/123orproduct/abcsuch a page is effective in the context. On these pages,archivethe variables have been assigned the complete data of the current document by the AnQi CMS system. Therefore,{{archive.Title}}This will directly output the title of the article or product you are currently visiting.

Consider a template structure for an article detail page:

{# 假设这是文章详情页的模板(例如 /template/default/article/detail.html)#}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>{{ archive.Title }} - {{ system.SiteName }}</title>
    <meta name="keywords" content="{{ archive.Keywords }}">
    <meta name="description" content="{{ archive.Description }}">
</head>
<body>
    <header>
        <h1>{{ archive.Title }}</h1> {# 页面主标题 #}
        <p>分类:<a href="{{ archive.Category.Link }}">{{ archive.Category.Title }}</a></p>
        <p>发布时间:{{ stampToDate(archive.CreatedTime, "2006-01-02 15:04") }}</p>
    </header>
    <main>
        <div class="article-content">
            {{ archive.Content|safe }} {# 输出文章正文,使用safe避免HTML转义 #}
        </div>
    </main>
    <footer>
        <p>&copy; {{ now "2006" }} {{ system.SiteName }}</p>
    </footer>
</body>
</html>

Here, {{archive.Title}}It directly corresponds to the article title of the current page. It is usually used to set the page<title>tags (crucial for SEO), the main title within the<h1>page, and filling in metadata (such askeywordsanddescriptionIt is the most direct statement of "What is" on the current page.

Context is king: the key to distinguishing between them.

UnderstandingitemandarchiveThe key is to grasp their context.Context (Context).

  • item.TitleIsLocal variable, its lifecycle and scope are limited to theforloop internal. Every time the loop comes to a new data item,itemit will be updated,TitleThe value will also change. It is used to handle the 'one-to-many' relationship, that is, displaying multiple same

Related articles

If a variable's value is an array or slice, how can you use a `for` loop in a template to iterate over and output its contents?

As an experienced website operations expert, I know that efficiently displaying dynamic data is very important in daily content management.AnQiCMS (AnQiCMS) leverages the powerful performance and flexible template system of the Go language to provide us with an excellent solution.Today, let's delve deeply into a practical and common scenario in AnQi CMS template development: how to use `for` loops to traverse arrays or slices and elegantly present their content on web pages.

2025-11-07

How to directly call built-in methods (such as getting thumbnails) of a Go language struct object in a template?

As an experienced website operations expert, I am well aware of the importance of an efficient and flexible CMS system for enterprise content management.AnQiCMS (AnQiCMS) leverages its powerful performance based on the Go language and the ease of use of the Django template engine, bringing us an unprecedented degree of freedom.In daily content operations, we not only hope that the data can be displayed accurately, but also hope that these data can come alive and be intelligently processed according to different needs.Today, let's delve into a seemingly advanced but actually very practical skill

2025-11-07

How do you access the internal properties of a Go language struct (struct) object by using the dot (.) character?

## How to cleverly use the (.) operator: The art of accessing Go struct attributes in Anqi CMS templates In modern website operations, an efficient and flexible content management system is the cornerstone of success.AnQiCMS (AnQiCMS), as an enterprise-level content management platform developed based on the Go language, has won the favor of many users with its high performance, security, and powerful customization capabilities.

2025-11-07

How to correctly display dynamic data variables passed from the backend or controller to the frontend in Anqi CMS template?

As an experienced website operations expert, I have been dealing with AnQiCMS (AnQiCMS) for many years in my daily work, and I am well aware of its efficient and flexible content management features.When using Anq CMS to build and maintain websites, a core and frequently encountered requirement is how to accurately display dynamic data passed from the backend or controller in the front-end template.Today, let's delve deeply into this topic and help everyone better master the template function of AnQiCMS

2025-11-07

How to display the current date and time in the Anqi CMS template and output them in a custom format?

As an expert with many years of experience in website operations, I am well aware of the importance of content timeliness and display professionalism to the value of the website.In an AnQiCMS content management system that is flexible and efficient, accurately controlling the display of dates and times on the page and formatting the output according to actual needs is an indispensable part of improving user experience and optimizing information delivery.Today, let's delve into how to display and format dates and times effortlessly in the AnQiCMS template.

2025-11-07

How to format time with the `now` tag, and which common Go language time formats are supported (such as year month day hour minute second)?

In the daily operation of AnQiCMS, we often need to handle various time information, whether it is to display the article publication date or dynamically display the current time on the page, an accurate and friendly format of time presentation is crucial for improving user experience and website professionalism.As an enterprise-level content management system built with Go language, AnQiCMS also inherits the unique style of Go language in time processing, especially in how the `now` tag formats time, which is worth in-depth exploration.### `now` tag

2025-11-07

How to automatically display the current year in the footer of a website (for example “© 2023”)?

As an experienced website operations expert, I am well aware of the importance of the details of website content, especially the subtle aspects such as the copyright year at the bottom of the website page, which not only concerns the professional image of the website but also indirectly affects the judgment of search engines on the freshness of the website content.In such an efficient and flexible content management system as AnQiCMS, achieving this is naturally easy.Today, let's talk about how to automatically display the current year in the footer of your website, keeping your website forever young!

2025-11-07

What is the special role of the `fake` parameter in the `now` tag, and in what scenarios would it be used?

As an experienced website operations expert, I have a deep understanding of AnQiCMS, an enterprise-level content management system developed based on the Go language.It is undoubtedly the powerful support for content operation with its high efficiency, flexibility, and is a capable assistant for small and medium-sized enterprises and self-media teams.In the process of dealing with templates every day, we always encounter various tags and parameters, which may seem trivial but can greatly affect development efficiency and content display effect.Today, let's delve into a seemingly mysterious yet extremely practical parameter - the `fake` parameter of the `now` tag.

2025-11-07