As an experienced website operations expert, I know that understanding the essence of template tags is the key to leveraging the powerful functions and building flexible pages in a high-efficiency content management system like AnQiCMS. Today, let's delve into a problem that often occurs when calling a single-page detail: “变量名称and字段名称What are the functions?
In the template system of AnQi CMS,pageDetailTags are specifically used to call detailed information of a single page. Whether it's fixed content pages like "About Us" or "Contact Information", or other custom independent pages,pageDetailCan all help us accurately obtain and display the required data. And when using this tag, we often see structures similar to{% pageDetail myPageTitle with name="Title" %}such as the syntax structure, of which the变量名称and字段名称Playing different roles while closely cooperating.
Field name: Specify what you want to obtain.
Firstly, let's talk about字段名称.It is like specifying a column of data you want to retrieve from the database in the CMS, clearly informing the AnQi CMS of the specific information you wish to extract from the current single-page call.字段名称isTitleIf you need to display the main content of the page, thenContent; Want the page description, it isDescription; The page's first image corresponds toLogo. Each字段名称points exactly to a specific attribute in the single-page data structure.
In simple terms,字段名称is used forDefine the specific data type you want to retrieve from a single page.It is a clear instruction you send to AnQiCMS: 'Please give me the title of this single page!'English or 'Please give me the content of this single page!'}]It determines the type of data you will receive, whether it is plain text, rich text content, an image link, or other page attributes.
Variable name: determines how you "receive" and "use" the data
Then, let's take a look at变量名称This part makes it more flexible, determining how to "accept" and "use".字段名称The data extracted.
You can choose not to set it.变量名称In this case, the safe 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 current single-page title 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 subsequent processing.
However, when your template logic becomes slightly more complex, or when you need to process and judge the same data multiple times,变量名称the advantages become evident. By specifying a变量名称You have created a temporary container in the template, which.字段名称The value obtained is stored 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 variable namedpageContentThe variable. Once assigned, you can use it inpageDetailthe closing tag of the{% endpageDetail %}to use it repeatedly{{ pageContent }}to refer to this content without needing to call it repeatedlypageDetailLabel.This practice not only improves the readability of template code and avoids repeated data queries, but more importantly, it enables you to perform more complex logic judgments and data processing in templates.For example, you can check if a variable exists, or decide what content 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 at the moment.':
{# 使用变量名称承接单页内容,便于后续判断和处理 #}
{% pageDetail pageContent with name="Content" %}
<div class="page-body">
{% if pageContent %}
{{ pageContent|safe }} {# 加上|safe过滤器以解析HTML内容 #}
{% else %}
<p>抱歉,此页面暂无内容。</p>
{% endif %}
</div>
{% endpageDetail %}
In this example,pageContentis变量名称It follows,ContentThis字段名称The single page main content represented by it. We judge whether the content is empty through it, thus realizing different display logic. If it is output directly, this kind of judgment cannot be made.if pageContentto determine whether the content is empty, thus achieving different display logic. If it is output directly, then this kind of judgment cannot be made.
Summary and extension
In short,字段名称It is your “pick-up certificate”, which clearly tells the system what data you want to take;“what” data you want to take.变量名称Then it is your “hand”, which determines how you “hold” and “use” the data after getting it.Gained an understanding of the functions of both, you can build rich and diverse single-page displays more efficiently and flexibly in the security CMS template.
In addition,pageDetailthe label also supportsidortokenParameters to accurately specify the single page to be called, for example.id='10'ortoken='about-us'. If you are managing multiple sites,siteIdParameters can also help you call data from specific sites. These parameters together constitutepageDetailTag powerful call capabilities, allowing you to flexibly obtain and display single-page information as needed.
Common Questions (FAQ)
Q1: I can get multiple tags in the samepageDetailtag at the same time字段名称?
A1: No.pageDetailEach time a tag is called, only one can be specified字段名称. If you need to get the title and content of a single page, you need to call it twicepageDetailLabel, or specify it in one of the calls变量名称to receive data, and then through anotherpageDetaillabel to get other fields. For example, get the title first, then get the content.
Q2: If I forget to givepageDetailSet tags变量名称,what will be the impact?
A2: If you do not set变量名称,pageDetailthe tag will be displayed directly字段名称The value is output to the template.This means you cannot refer to this value again in subsequent template code, nor can you perform direct template logic judgment on it or combine it with other data.变量名称.
Q3: Why in the call of single page contentContentauto|safeFilter?
A3:ContentThe field usually contains HTML code generated by the backend editor.The security CMS, for safety reasons, defaults to escaping all output content as HTML entities to prevent cross-site scripting (XSS) attacks.|safeauto