Does the `prevArchive` tag support getting custom field content from the backend of the previous document?

Calendar 👁️ 61

As an experienced website operation expert, and with a deep understanding of AnQiCMS template tags and content operation strategies, I am happy to give you a detailed explanationprevArchiveThe function of the tag, and how to cleverly obtain the custom field content of the previous document.


An in-depth analysis of Anqi CMSprevArchiveTag and custom field acquisition strategy

In the template development of AnQi CMS,prevArchiveandnextArchiveTags are commonly used tools for navigating the front and back of documents.They aim to provide a concise and efficient way for visitors to easily jump to the previous or next related content after reading the current article, thereby enhancing user experience and page browsing depth.prevArchiveDoes the tag support directly accessing the custom field content of the previous document in the backend, which is indeed a common question among many developers and operators.

From the design philosophy of Anqi CMS template tags,prevArchiveThe core positioning of tags is to provideLightweight, fast responseNavigation data.This means it will only output some basic and commonly used information from the previous document, so that the template can quickly render the title, link, thumbnail, and other navigation elements of the previous document.

Unfortunately, pass directly through{% prevArchive prev %}This way, you cannot get the custom field content set in the background of the previous document.

Consulttag-prevArchive.mdDocument,prevArchiveThe fields explicitly supported by the tag include:Id(Document ID),Title(Document Title),Link(Document Link),Keywords(Document keywords),Description(Document description),CategoryId(Document Category ID),Views(Document Views),Logo(Cover main image),Thumb(Cover Thumbnail),CommentCount(Number of Comments),CreatedTime(Add Time) andUpdatedTime(Updated time). This list does not include user-defined fields.

Then, does this mean that our needs cannot be met?Of course not.AnQi CMS provides a flexible template tag system, and we can cleverly achieve the goal by combining different tags.

Circumvent the country: throughprevArchiveGet the ID, then usearchiveDetailGet complete information

To obtain the custom field content of the previous document, we need to take a two-step approach:

  1. First step: useprevArchiveLabel to obtain the previous document'sId. prevArchiveThe label returns an object containing basic information about the previous document (such as in{% prevArchive prev %}isprev). This object contains the unique identifier we need—the document ID.
  2. The second step: Use the ID of the previous document obtained, combinedarchiveDetailwith tags to get the complete details of the document, including all custom fields. archiveDetailTags are powerful tools for obtaining detailed information about any document, it supports accessing through document ID (idSpecify the document to be queried by a parameter, and it can return complete data including all custom fields.

Let's demonstrate this process with a specific code example:

{# 1. 使用 prevArchive 标签,将上一篇文档数据赋值给 prev 变量 #}
{% prevArchive prev %}
  {% if prev %}
    {# 确保存在上一篇文档,然后获取其ID #}
    {% set prevDocId = prev.Id %}

    {# 2. 使用 archiveDetail 标签,通过 prevDocId 获取上一篇文档的完整数据 #}
    {% archiveDetail fullPrevDoc with id=prevDocId %}
      <h3>上一篇:<a href="{{ fullPrevDoc.Link }}">{{ fullPrevDoc.Title }}</a></h3>
      <p>常规描述:{{ fullPrevDoc.Description }}</p>

      {# 直接通过变量名访问自定义字段,例如假设您有一个名为 'author' 的自定义字段 #}
      {% if fullPrevDoc.author %}
        <p>作者(自定义字段):{{ fullPrevDoc.author }}</p>
      {% endif %}

      {# 如果您需要循环显示所有自定义字段,可以使用 archiveParams 标签 #}
      {% archiveParams prevDocCustomParams with id=prevDocId %}
        {% for param in prevDocCustomParams %}
          {# 这里显示自定义字段的名称和值 #}
          <p>{{ param.Name }}:{{ param.Value }}</p>
        {% endfor %}
      {% endarchiveParams %}
    {% endarchiveDetail %}
  {% else %}
    <p>没有上一篇了。</p>
  {% endif %}
{% endprevArchive %}

In this code, we first useprevArchivegotprevan object and extracted from itprev.Id. Then, we passed this ID toarchiveDetaillabel'sidthe parameter and assigned the complete document data obtained tofullPrevDoc. At this point,fullPrevDocThe object includes all the information from the previous document, including the various custom fields defined in the backend content model. You can accessarchiveDetailReturns the current document fields as is, passes through directlyfullPrevDoc.您的自定义字段名To access them. If needed, you can even pass through them.archiveParamsThe label is retrieved again based on ID and loops through all custom fields to achieve more flexible display.

This method, although it adds an extra step compared to direct access, fully utilizes the flexibility and powerful functions of the Anqi CMS template tags, ensuring that you can obtain any data you need.In practice, due to the excellent performance of AnQi CMS, which is developed based on Go language, even with an additional query operation, it usually will not cause a significant impact on the website's loading speed.


Frequently Asked Questions (FAQ)

  1. Q: Why?prevArchiveWhy does the label not provide all fields directly, including custom fields?A:prevArchiveThe design intention of the label is to provide quick and lightweight navigation data.Under most circumstances, the previous/next article navigation only needs to display the title, link, and other basic information.If the default loading of all fields (including potentially a very large number of custom fields) is enabled, it will increase the complexity of database queries and the amount of data transfer, thereby affecting the rendering efficiency of the page.prevArchiveandarchiveDetailThe function, Anqi CMS can provide **performance in different scenarios.

  2. Q: Can IarchiveDetailDo you get the information of the previous document directly through the document title or URL alias in the tag, instead of the ID?A: Yes, you can.archiveDetailTags not only supportidParameters, but also support throughtoken(The URL alias of the document) to obtain document details. Therefore, if you can obtain the URL alias of the previous document,prevArchiveyou can pass it to the next document as well,archiveDetailoftokenParameters are used to obtain complete information. However, obtaining the ID is usually the most direct and efficient way, as the ID is the primary key in the database.

  3. Q: If the previous document I retrieve does not contain the content of a custom field, will the template report an error?A: Usually, it will not report an error. If throughfullPrevDoc.您的自定义字段名The custom field being accessed has no value (for example, not filled in on the backend), it will return an empty string or zero value without causing any template parsing error. To better control the display, you can use it in the template.{% if fullPrevDoc.您的自定义字段名 %}Make a judgment, only display the field when there is content to keep the page tidy.

Related articles

How to format the `CreatedTime` or `UpdatedTime` obtained from the `prevArchive` tag into a readable date and time?

In website operation, the time of content release or update is an important part of conveying information to users.A clear and readable date-time format, which can not only improve the user experience but also enhance the professionalism and timeliness of the content.However, many content management systems typically use a string of timestamps that are difficult to understand intuitively.

2025-11-07

Can the `prevArchive` tag retrieve the `Description` (summary) field of the previous document?

Sure, as an experienced website operations expert, I am happy to delve into the usage of the `prevArchive` tag in AnQi CMS and answer questions about obtaining the Description field of the document. --- ## Unlock Anqi CMS `prevArchive` tag: Easily get the summary of the previous document In daily website operations, we often need to provide users with a smooth reading experience and guide them to discover more related content. This includes

2025-11-07

The document for the previous archive tag is determined by what logic or sorting rules?

## Unveiling the Anqi CMS `prevArchive` tag: The intelligent sorting logic of the "Previous" document As an experienced website operations expert, I know that behind each CMS tag lies the potential to enhance user experience and SEO efficiency.AnQiCMS (AnQiCMS) is known for its efficiency and flexibility, and its template tag system is an extremely powerful tool for content operations.Today, let's delve into a seemingly simple but actually cleverly logical tag: `prevArchive`, and how it intelligently determines what we mean by 'previous document'

2025-11-07

How to add custom CSS styles or HTML attributes to the link generated by the `prevArchive` tag?

As an experienced website operations expert, I am well aware of the importance of meticulous template customization in content management systems for enhancing user experience and the overall style of the website.AnQiCMS (AnQiCMS) provides us with great flexibility with its efficient architecture based on the Go language and a Django-like template engine.Today, let's delve into a common customization requirement: how to add custom CSS styles or HTML attributes to the link generated by the `prevArchive` tag for the 'previous article'.

2025-11-07

How to avoid the `prevArchive` tag from outputting an empty value or causing a template error when there is no previous document?

As an experienced website operations expert, I know that the robustness of templates in content management systems is crucial for the stable operation of the website and the user experience.AnQiCMS with its efficient and flexible template system has won the favor of many users, but even an excellent system needs to master some skills in practical application to fully exert its power.Today, let's delve deeply into a common but often overlooked issue in AnQiCMS template development: how to avoid the `prevArchive` tag from outputting an empty value or causing the template to error when there is no previous document

2025-11-07

How to effectively use the `prevArchive` tag to enhance the internal link structure and user navigation experience of a website?

## Unlock AnQi CMS `prevArchive` tag: A comprehensive guide to effectively optimizing internal links and user navigation experience In today's increasingly user experience and search engine optimization-focused era, the internal link structure and navigation fluidity of a website are particularly important.As an experienced website operations expert, I am well aware of the powerful potential of AnQiCMS (AnQiCMS) in content management and SEO.

2025-11-07

Can the `prevArchive` tag retrieve the `Keywords` (keywords) field of the previous document?

As an experienced website operations expert, I know that a detailed understanding of each tag (Tag) function in a content management system can bring a qualitative leap in the operational efficiency and SEO performance of the website.Today, let's delve deeply into a very practical template tag in AnQiCMS (`prevArchive`), focusing on whether it can retrieve the `Keywords` field of the previous document.

2025-11-07

Which document properties can be directly accessed from the `prev` variable returned by the `prevArchive` tag?

In the powerful feature matrix of AnQi CMS, providing users with a smooth site navigation experience is crucial, and the `prevArchive` tag is one of the key factors to achieve this goal.It allows us to easily obtain and display information about the "previous" document on the current document page, greatly enhancing the continuity of user reading and the interaction of the website.

2025-11-07