As an experienced website operations expert, I have accumulated rich experience in the practice of content management systems (CMS), especially for the powerful functions and flexible application of AnQiCMS (AnQiCMS).Today, let's delve deeply into a seemingly basic but crucial issue in website operation: how to elegantly and accurately call and display the article title on the document detail page of AnQiCMS.This not only concerns the basic content presentation of the page, but also directly affects the user experience and SEO effect.
Understand the template mechanism of AnQiCMS
AnQiCMS with its high efficiency and ease of use has won the favor of many small and medium-sized enterprises and content operators.The template system uses a syntax similar to the Django template engine, making template customization and development intuitive and flexible..htmlAs a suffix, it is stored in the root directory of the websitetemplatein the folder.
During the process of writing template files, you will mainly come into contact with two types of tags:
- Logical control tags
{% ... %}These tags are used for executing flow control, such as loops ({% for ... %}), conditional judgments ({% if ... %}) and introducing other template fragments ({% include ... %}) and so on. - Variable output tag
{{ ... }}These tags are used to directly output data, such as article titles, content, and publication time. The system will inject the processed data into the positions of these tags.
Understanding the functional distinction of these two tags is the basis for efficiently using the AnQiCMS template system.
Locate the document detail page template
To display the article title, we first need to find or create the corresponding document detail page template.The template structure of AnQiCMS is very flexible, it follows a conventional naming convention.{模型table}/detail.html.
For example, if your article content belongs to the built-in "article" model of the system, the model table name is usuallyarticleThen the corresponding document detail page template file is probably/template/您的模板名称/article/detail.htmlWhen a user visits any article's detail page, the AnQiCMS system will automatically load this template file to render the page content.
Of course, AnQiCMS also supports specifying independent templates for specific documents or categories, for example, you can createarticle/detail-123.htmlProvide a dedicated template for the article with ID 123. This flexibility is very useful when it is necessary to display a few important contents uniquely.
Core tags and direct variable calls: Displaying two methods of article titles
In the document detail page of AnQiCMS, the system has intelligently loaded all the data of the current document into the rendering context (context).This means that you can directly access the various properties of the article without manually querying the database.
Method one: Go through directlyarchiveObject access (recommended)
This is the most direct and commonly used method. In any document detail page template, the system will automatically provide a name calledarchiveThe object contains all the details of the current document. Therefore, to display the article title, you simply use{{ archive.Title }}Just do it.
Herearchiverepresents the document data loaded on the current detail page, and.TitleThis accurately points to the article's title field. This method is concise and easy to understand and use.
Example code snippet:
<h1>{{ archive.Title }}</h1>
Method two: usearchiveDetailTag
Although{{ archive.Title }}Can meet most needs, but you may need to use it in certain specific scenariosarchiveDetailLabel. For example, when you need to use it on a non-document detail page, or when you need to specify the title of a document with a certain ID,archiveDetailit becomes very useful.
archiveDetailThe tag is used to obtain detailed data of the document. When used withoutidparameters, it intelligently retrieves the title of the current document.
Basic usage:
{% archiveDetail with name="Title" %}
If you want to get the title of a document with a specified ID (for example, referencing a specific article title in the sidebar or other blocks), you can write it like this:
{% archiveDetail with name="Title" id="123" %}
Hereid="123"Indicate that you want to retrieve the article title with ID 123.
Practical application: Display the article title on the page.
Now, let's integrate this knowledge into the actual template file. Assume you are editingarticle/detail.htmlA template file, to ensure SEO-friendliness and provide a good user experience, the main title of the article usually uses<h1>tag wrapping.
The following is a simplified document detail page template example, showing how to call the article title and some common auxiliary information:
`html <!DOCTYPE html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- 使用tdk标签获取页面的SEO标题,并附加网站名称 -->
<title>{% tdk with name="Title" siteName=true %}</title>
<meta name="keywords" content="{% tdk with name="Keywords" %}">
<meta name="description" content="{% tdk with name="Description" %}">
<!-- 其他CSS文件和元数据 -->
<header>
<!-- 这里通常是网站的Logo、导航菜单等公共元素 -->
<!-- 例如:{% include "partial/header.html" %} -->
</header>
<main class="container">
<article class="article-detail">
<!-- 核心:展示文章标题 -->
<h1>{{ archive.Title }}</h1>
<div class="article