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