What are the respective roles of `variable name` and `field name` when calling the single-page detail?

Calendar 👁️ 77

As an experienced website operations expert, I am well aware that understanding the essence of template tags is the key to unleashing the powerful functions and building flexible pages in a high-efficiency content management system like AnQiCMS. Today, let's delve into a frequently encountered problem when calling the details of a single page: 变量名称and字段名称What are the functions?

In the AnQi CMS template system,pageDetailTags are specifically used to call detailed information of a single page. Whether it is a fixed content page such as "About Us" or "Contact Information", or other custom independent pages,pageDetailCan help us accurately obtain and display the required data. When using this tag, we often see similar{% pageDetail myPageTitle with name="Title" %}such syntax structure, among which the变量名称and字段名称Playing different roles, yet working closely together.

Field name: Clearly specify what you want to obtain.

First, let's talk about it.字段名称. It is like specifying a column of data to retrieve from a database, clearly telling AnQi CMS which specific information you want to extract from the current single page call.For example, if you want to get the title of the page, then字段名称that isTitle; If you need to display the main content of the page, that is.Content; wanting the page description, it isDescription; while the page header image corresponds toLogo. Each字段名称accurately points to a specific attribute in the single-page data structure.

In simple terms,字段名称The function isDefine the specific data type you want to retrieve from the single page. It is a clear instruction you have given to AnQiCMS: 'Please give me the title of this single page!'Or "Please provide the content of this single page!" It determines what type of data you will receive, whether it is plain text, rich text content, image link, or other page properties.

Variable name: Determines how you "receive" and "use" the data

Next, let's take a look at变量名称This part becomes more flexible, it determines how you go about 'accepting' and 'using'字段名称The data extracted.

You can choose not to set it.变量名称In this case, Anqi CMS will directly output字段名称the corresponding value to the template. For example,<div>页面标题:{% pageDetail with name='Title' %}</div>This line of code will directly display the title of the current page without storing it in any variable.This method is simple and direct, suitable for scenarios where you only need to output a field once and do not require further processing.

However, when your template logic becomes slightly more complex, or when you need to process and judge the same data multiple times,变量名称the advantage becomes evident. By specifying a particular变量名称This is equivalent to creating a temporary container in the template, which will字段名称Store the value obtained in this container.

For example,{% pageDetail pageContent with name='Content' %}This line of code will assign the main content of the current single-page to a namedpageContentThe variable. Once assigned, you can usepageDetailThe closing tag of the tag{% endpageDetail %}within, repeatedly use{{ pageContent }}to refer to this content without repeating the callpageDetailTags. This approach not only improves the readability of template code and avoids repeated data queries, but more importantly, it empowers you to perform more complex logical judgments and data processing in the template.For example, you can check if a variable exists or decide what to display based on the variable's value.

For example, we want to display the content of a single page, if the content is empty, then display 'Sorry, this page has no content.':

{# 使用变量名称承接单页内容,便于后续判断和处理 #}
{% pageDetail pageContent with name="Content" %}
    <div class="page-body">
        {% if pageContent %}
            {{ pageContent|safe }} {# 加上|safe过滤器以解析HTML内容 #}
        {% else %}
            <p>抱歉,此页面暂无内容。</p>
        {% endif %}
    </div>
{% endpageDetail %}

In this example,pageContentthat is变量名称It followed.ContentThis字段名称The content represented by the single-page main body. We use it to judge whether the content is empty, thus realizing different display logic. If it is output directly, this judgment cannot be made.if pageContentto determine if the content is empty, thus achieving different display logic. If it is output directly, this judgment cannot be made.

Summary and extension

In short,字段名称It is your 变量名称It is your 'hand', which determines how you 'hold' and 'use' the data you receive.Mastering the functions of both can enable you to build diverse and rich single-page displays more efficiently and flexibly in the Anqi CMS template.

Furthermore,pageDetailThe tag also supports passing throughidortokenParameters to accurately specify the single page to be called, for exampleid='10'Ortoken='about-us'. If you are managing multiple sites,siteIdParameters can also help you call data from specific sites. These parameters together constitutepageDetailThe powerful calling ability of tags allows you to flexibly obtain and display one-page information as needed.

Frequently Asked Questions (FAQ)

Q1: Can I get multiplepageDetailtags at the same time字段名称?

A1: No.pageDetailEach tag can only be specified once when called字段名称. If you need to get the title and content of a single page, you need to call it twice separatelypageDetailLabel, or specify it in one of the calls变量名称to receive data, and then pass through anotherpageDetailLabel to get other fields. For example, first get the title, then get the content.

Q2: If I forget to givepageDetailLabel settings变量名称what would be the impact?

A2: If you do not set变量名称,pageDetailthe tag will directly字段名称The value is output to the template. This means you cannot reference this value in subsequent template code, nor can you perform direct template logic or combine it with other data.For simple content output, this may not be a problem; but for situations that require data reuse or processing, it is recommended to use变量名称.

Q3: Why when calling single page contentContentWhen, it is usually necessary to add|safeFilter?

A3:ContentThe field usually contains HTML code generated by the backend editor.The AnQi CMS, for security reasons, defaults to escaping all output content with HTML entities to prevent cross-site scripting (XSS) attacks.If you do not use|safeFilter, this HTML code will be displayed as plain text and not parsed by the browser as

Related articles

What is the basic syntax and necessary parameters of the `pageDetail` tag?

As an experienced website operations expert, I know that proficiently using template tags in a high-efficiency content management system like AnQiCMS is the key to improving operational efficiency and achieving personalized content display.Today, let's delve into a very practical tag - `pageDetail`, which can help us easily obtain and display the content of independent pages on websites.

2025-11-07

How to call the detailed information of a specific page in Anqi CMS template?

AnQi CMS, as an efficient and flexible content management system, has provided strong support for us in the field of content operation.In daily website management, single-page (also known as independent page) plays an indispensable role, whether it is to showcase corporate culture in "About Us", provide a communication bridge in "Contact Us", or introduce various service pages, they are all important windows for users to obtain core information.

2025-11-07

How to format timestamps with the `stampToDate` tag in AnQiCMS template?

As an experienced website operations expert, I know that in daily content management, timestamp formatting is a seemingly simple detail that often troubles many operations personnel.In AnQiCMS such an efficient and flexible content management system, mastering the use of template tags can greatly enhance the professionalism and user experience of content presentation.Today, let's delve into a very practical and key tag in the AnQiCMS template - `stampToDate`, and see how it helps us easily format timestamps.

2025-11-07

How to use `if` and `for` tags for logical judgment and loop traversal in AnQiCMS templates?

As an experienced website operations expert, I am well aware of the importance of a flexible and powerful template system for content management.AnQiCMS leverages its high-performance architecture based on the Go language and support for Django template engine syntax, providing us with great convenience.It is not just a tool for publishing content, but also a powerful tool for us to achieve personalized content display and improve user experience.

2025-11-07

How will the content be directly output if the `variableName` of the `pageDetail` tag is not set?

## Unlock the secrets of Anqi CMS single page content output: The power of the simple `pageDetail` tag As an expert in website operations for many years, I know that efficiently and flexibly displaying content is the key to success in daily content management.AnQiCMS (AnQiCMS) is an enterprise-level content management system developed based on the Go language, and its simple and efficient template engine is very appealing to me.It provides great convenience in content display, especially for single-page content (such as "About Us", "Contact Information", etc.)

2025-11-07

How to accurately obtain the details of a single page through the single page ID?

As an experienced website operations expert, I know that how to efficiently and accurately obtain the required data in a content management system is the key to improving operational efficiency.In AnQiCMS (AnQiCMS), a single page (or independent page) is often used to display 'About Us', 'Contact Information', 'Service Introduction', and other important but infrequently changing content.Sometimes, we not only need to display the details on the single page itself, but may also need to reference part of the specific page information on other parts of the website (such as the homepage, sidebar).

2025-11-07

Is the `id` parameter of the `pageDetail` tag required?

## AnQiCMS `pageDetail` tag's `id` parameter: Optional flexible art As an experienced website operations expert, I am well aware of the importance of the flexibility of content management system templates in improving operational efficiency and website performance.AnQiCMS (AnQiCMS) boasts its concise and efficient architecture, which is also reflected in the design of template tags.

2025-11-07

By default, the `pageDetail` tag will retrieve data for which single page?

In the powerful functional system of AnQi CMS, flexibly using various tags is the key to improving efficiency for website operators and template developers.Today, let's delve deeply into a tag that is indispensable in building static content pages - `pageDetail`, and focus particularly on the core issue of which single page of data it will retrieve by default. ### Exploring `pageDetail`: How does it intelligently retrieve data?

2025-11-07