Understanding the detail page of document tags in Anqi CMS

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

The template design of Anqi CMS follows a set of intuitive conventions, which will automatically match 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 typically search for and applytag/list.html(In folder organization mode) ortag_list.html(In flat organization mode) as its main template.This means, if you want to design a completely different layout for the tag detail page, the most direct method is to customize these dedicated template files.

However, sometimes we may not want to create an independent template for each label detail page, but rather prefer to use a general layout file (such as the one for the website'sbase.htmlor headerpartial/header.html)In this case, the content or style of certain blocks is dynamically adjusted based on whether the current page is a tag detail page. This requires us to introduce conditional judgment logic in 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 ingeniously utilize the functions provided by the Safe CMStagDetailLabel. The function of this label is to obtain the detailed information of the current page's label. If the current page is indeed a label detail page,tagDetailThe label will be able to successfully retrieve the data for this label, such as its ID, title, description, etc. Conversely, if the current page is not a label detail page (such as an article detail page, category list page, or homepage), thentagDetailThe label will not be able to retrieve valid label 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,{%- tagDetail currentTagId with name="Id" %}It will try to assign the current page's label ID tocurrentTagIdVariable. This is-used to remove extra whitespace characters generated by label lines to maintain code neatness. If the assignment is successful (i.e."),currentTagIdhas a value), then{% if currentTagId %}This condition will be met, thus executing the special layout code for the label detail page.

This judgment logic can be placed in any template file of the website, including the general ones.base.htmlOr be,includeNavigate to each page.partial/header.htmlSo that conditional layout adjustments can be implemented throughout the site.

Create a dedicated layout: two practical strategies.

Once we can accurately determine the type of the current page, we can proceed to implement special layouts. Here are two commonly used 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'stitleWhen adding a special header banner or changing the display content of the sidebar, this strategy is very applicable. You can find this in the general layout files of the website (such asbase.html)or the imported public fragment(such aspartial/header.html)used aboveifcondition judgment.

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

Assuming yourbase.htmlincludes<title>label and welcome information at the top of the page:

English

<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>