How to determine whether the current page is the detail page of a document tag and perform special layout?

Calendar 👁️ 58

As an experienced website operations expert, I know that how to flexibly customize page layout in a content management system is crucial for improving user experience and optimizing SEO.AnQiCMS (AnQiCMS) leverages its powerful template engine and rich tag features to provide us with the tool we need to achieve this goal.Today, let's delve deeply into a common and practical need: how to determine whether the current page in AnQi CMS is a detail page of a document tag and apply a unique layout for it.

Understanding the document tag detail page in Anqi CMS

In AnQi CMS, document tags (Tag) are an important way to organize content.When a user clicks on a tag or accesses the aggregated content of a tag directly through a URL, we will usually enter a 'document tag detail page'.This page is mainly responsible for displaying all relevant documents under the tag, and may also accompany some introduction information about the tag itself.

The template design of AnQi CMS follows a set of intuitive conventions, which automatically matches the corresponding template file based on the URL path. For example, for a page displaying a document list under a certain tag, the system will usually search for and applytag/list.html(In folder organization mode) ortag_list.html(In flat organization mode) it serves as the main template. This means that if you want to design a completely different layout for the label detail page, the most direct method is to customize these exclusive template files.

However, sometimes we may not want to create an independent template for each tag detail page, but rather hope to have a generic layout file (like the websitebase.htmlor headerpartial/header.htmlIn this case, based on whether the current page is a tag detail page, we dynamically adjust the content or style of certain blocks. This requires us to introduce conditional judgment logic from the template.

Core judgment mechanism: Is the current page a tag detail page?

To determine whether the current page is a document tag detail page, we can cleverly utilize the Anqi CMS providedtagDetailTag. This tag is used to retrieve the detailed information of the current page. If the current page is indeed a tag detail page, thentagDetailThe tag can successfully retrieve the data of the tag, such as its ID, title, description, etc. Conversely, if the current page is not the tag detail page (such as the article detail page, category list page, or homepage), thentagDetailThe tag cannot retrieve valid tag data.

Based on this principle, we can construct a simple conditional judgment:

{%- tagDetail currentTagId with name="Id" %} {# 尝试获取当前页面的Tag ID #}
{% if currentTagId %}
    {# 代码块:当前页面是标签详情页时执行 #}
    {# 在这里,你可以访问 {% tagDetail with name="Title" %} 来获取标签标题等信息 #}
{% else %}
    {# 代码块:当前页面不是标签详情页时执行 #}
{% endif %}

In this code block,{%- tagDetail currentTagId with name="Id" %}It will try to assign the current page tag ID tocurrentTagIdVariable. This-symbol is used to remove extra whitespace from label lines to maintain code neatness. If the assignment is successful (i.e.currentTagIdthere is a value), then{% if currentTagId %}This condition will be met, thus executing the unique layout code of the tag detail page.

This judgment logic can be placed in any template file of the website, including the generalbase.htmlor beincludeto each pagepartial/header.htmlso that conditional layout adjustments can be implemented throughout the website.

Create a custom layout: two practical strategies

Once we can accurately determine the type of the current page, we can start implementing special layouts. Here are two common strategies that you can choose according to your actual needs:

Strategy one: Make conditional judgments and content adjustments in the general template (suitable for local fine-tuning)

When you only need to adjust some local elements on the tag detail page, for example, modify the page'stitleAdd a special header banner or change the display content of the sidebar, this strategy is very applicable. You can do this in the general layout file of the website, such asbase.htmlOr public fragments such aspartial/header.htmlUsed as described aboveifConditional judgment.

Example scenario: Set a unique page title and introduction for the tag detail page

Suppose yourbase.htmlContains<title>Tag and welcome information at the top of the page:

`twig {# base.html #} <!DOCTYPE html>

<meta charset="UTF-8">
{%- tagDetail currentTagId with name="Id" %}
{% if currentTagId %}
    {# 标签详情页的专属标题和描述 #}
    <title>{% tagDetail with name="Title" %} - 相关文档 - {% system with name="SiteName" %}</title>
    <meta name="description" content="关于{% tagDetail with name="Title" %}标签的所有相关文档和信息。{% tagDetail with name="Description" %}">
{% else %}
    {# 其他页面的通用标题和描述 #}
    <title>{% tdk with name="Title" siteName=true %}</title>
    <meta name="description" content="{% tdk with name="Description" %}">
{% endif %}
{# 其他通用 head 内容 #}

<header>
    {%- tagDetail currentTagId with name="Id" %}
    {% if currentTagId %}
        <div class="header-tag-banner">
            <h1>标签:{% tagDetail with name="Title" %}</h1>
            <p>{% tagDetail with name="Description"|default:"探索与此标签相关的所有精彩内容。" %}</p>
        </div>
    {% else %}
        <div class="header-general-banner">
            <h1>欢迎来到我们的网站</h1>

Related articles

How to design and display a beautiful tag cloud (Tag Cloud) on a frontend page?

AnQiCMS is an enterprise-level content management system developed based on the Go language, which is favored by many small and medium-sized enterprises and content operation teams for its high efficiency, customization and ease of expansion.As an expert in website operations for many years, I deeply understand the importance of content display strategy for attracting users and improving SEO performance.Today, let's talk about how to design and display a beautiful and practical Tag Cloud on the AnQiCMS frontend page.

2025-11-06

How to implement the `limit` parameter of the `tagList` tag to start displaying from the Nth tag?

As an expert deeply familiar with the operation of Anqing CMS content, I am delighted to delve into the巧妙用法 of the `limit` parameter in the `tagList` tag, especially how to achieve the advanced function of displaying from the Nth tag.This can bring great flexibility to content layout and user experience in actual website operations.

2025-11-06

If the document tag has a content field (Content), how to use the `render=true` parameter to correctly display Markdown content?

As an experienced website operations expert, I am more than happy to explain in detail how to skillfully use the `render=true` parameter to correctly and beautifully display Markdown content when the document tag contains the content field (Content) in Anqi CMS.This is not only about technical implementation, but also the key to improving the presentation effect and reader experience.

2025-11-06

What is the use of the 'index letter' function of document tags, and how to apply it in the front-end template?

As an experienced website operations expert, I am happy to delve into the mysteries of the 'Index Letter Function' of the Anqi CMS and its application in the front-end template.This seemingly simple feature actually contains great potential to improve user experience, optimize information architecture, and even help with SEO. --- ## The Index Letter Function of Tags: The 'Guiding Light' of Content Organization in AnQi CMS Tags (Tag) are an important tool for organizing content and establishing associations in content management systems.

2025-11-06

How is the link of the document tag automatically generated in the front-end template?

AnQiCMS (AnQiCMS) has always been committed to providing both efficient and flexible solutions in content management. Among them, the document tag (Tag) serves as an important tool for content organization and SEO optimization. The link generation mechanism in the front-end template even reflects the exquisite design of the system.As an experienced website operations expert, I am well aware of the importance of a clear and friendly URL structure for user experience and search engine rankings.Today, let's delve into how Anqi CMS automates the generation of these valuable tag links.### One, Tag (Tag) is in

2025-11-06

How to implement sorting tags such as `{% tagList %}` by popularity (for example, by the number of associated documents)?

As an experienced website operations expert, I am well aware of the importance of tag management for content organization and user discovery.In an efficient content management system like AnQiCMS, how to intelligently display tags, especially sorting by popularity, is a concern for many content operators.Today, let's delve into the `{% tagList %}` tag and its capabilities and challenges in implementing the sorting of popular tags.### Explore the potential of tags: An overview of the tag function in AnQi CMS In AnQi CMS

2025-11-06

How to use document tags to enhance the internal link structure of website content and improve user navigation experience?

## How to cleverly use AnQi CMS document tags to weave a content link network and optimize user exploration experience As an experienced website operations expert, I know that the core value of a content management system (CMS) is not only in the efficiency of content publishing, but also in how to make these contents easily discovered by users and generate greater value.AnQiCMS (AnQiCMS) provides a strong support for small and medium-sized enterprises and content operators with its concise and efficient architecture.Today, let's delve deeply into a seemingly simple yet potentially powerful feature in Anqi CMS - **Document Tags**

2025-11-06

How to efficiently apply various data filters in Anqi CMS templates?

AnQi CMS, as an enterprise-level content management system built based on the Go language, has won the favor of many small and medium-sized enterprises and content operators with its efficient, secure, and flexible features.In daily content management and front-end display, we often need to process and present data in a fine-grained manner, which cannot be separated from the powerful data filtering function in the template.This article will delve into how to efficiently apply various data filters in the AnQiCMS template, making your content display more expressive and practical.###

2025-11-06