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

Calendar 👁️ 61

Unlock the mystery of AnQi CMS single page content direct output:pageDetailThe power of concise tags

As an expert who has been deeply involved in website operation for many years, I know that effectively 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 concise and efficient template engine is deeply to my liking.It provides great convenience in content display, especially for single-page content (such as "About Us", "Contact Information", etc.)

Today, let's delve into a seemingly simple but thought-provoking template tag in AnQi CMS -pageDetail. When we do notpageDetailLabel settings变量名称How content is directly outputted, and what advantages this method can bring in actual operation.

pageDetailThe basics of tags and direct output mechanism

In the template design of AnQi CMS,pageDetailTags are specifically used to retrieve and display detailed information about a single page. It allows us to specifynameparameters to accurately extract specific fields of a page, such as the page title (Title)、Page Content(Content)、Page Description(Description) and so on.

Its cleverness lies in its flexible output mechanism. The official documentation clearly states: 'Variable names are not required. After setting a variable name, subsequent calls can be made through the variable name, and if a variable name is not set, the result is output directly.'This means, when we use it like thispageDetailLabeling time:

<div>单页标题:{% pageDetail with name="Title" %}</div>
<div>单页描述:{% pageDetail with name="Description" %}</div>

The template engine parses to{% pageDetail with name="Title" %}and will immediately query the current page title (or throughidortokenThe specified page title) and insert its value directly into the position of the tag, forming a complete HTML content.Similarly, the page description will also be output in the same way.The entire process does not require us to assign the content to a temporary variable before outputting, which greatly simplifies the code.

the actual application scenario of content output directly

This direct output feature is particularly practical in many common website operation scenarios:

  1. Page title (Title) and meta descriptions (Description)In<head>the page of regional settings<title>Tags and<meta name="description">When labeling, we usually just need to directly output the values of these fields.

    <title>{% tdk with name="Title" %}</title> {# 使用tdk标签获取标题更通用,这里以pageDetail为例 #}
    <meta name="description" content="{% pageDetail with name="Description" %}">
    

    No additional variables are needed, the code is clear at a glance, directly obtained and presented from the background database.

  2. The main content of the page (Content): The most efficient way is to output directly for the core content area of a single page, such as the long text introduction on the "About Us" page.

    <article class="main-content">
        {% pageDetail pageContent with name="Content" %}
        {{ pageContent|safe }} {# 注意:如果内容包含HTML标签,需要使用|safe过滤器防止被转义 #}
    </article>
    

    Here, I wrote an extra step for safety, assigning topageContentVariable. But if you want to write the code in the most concise way, you can directly write:

    <article class="main-content">
        {% pageDetail with name="Content" render=true|safe %} {# render=true 确保Markdown内容被正确渲染,|safe 防止HTML标签被转义 #}
    </article>
    

    AnQiCMS'pageDetailThe tag is output directlyContentWhen the field contains HTML,By default, it will be HTML-escaped for safetyTherefore, if you want the HTML content to be normally parsed and displayed by the browser, you must cooperate.|safeFilter usage. If the content is in Markdown format, you can also addrender=trueparameters to let the system convert it to HTML before outputting, and then pass|safeEnsure rendering.

  3. image links (LogoorThumb)When it is necessary to display a single-page thumbnail or Banner image, the image URL can be output directly to thesrcattribute, which is also a convenient practice.

    <img src="{% pageDetail with name="Logo" %}" alt="{% pageDetail with name="Title" %}" class="page-header-image">
    

These scenarios have the common feature that the processing of the content is limited to 'retrieve and display', without the need for complex secondary processing, judgment, or repeated references in templates.The direct output mechanism greatly reduces the redundancy of template code, improves development efficiency and readability.

When is it necessary to name variables? (Comparative thinking)

Of course, not all situations are suitable for direct output. When we really need to process the content of a single page further, it ispageDetailIt is very necessary to specify a variable name with a tag. For example:

  • Data processing againIf you need to truncate the title of a single page, perform case conversion, or make conditional judgments based on content length.
    
    {% pageDetail pageTitle with name="Title" %}
    <p>处理后的标题:{{ pageTitle|truncatechars:10 }}</p>
    {% if pageTitle|length > 20 %}
        <p>标题较长,可能需要优化。</p>
    {% endif %}
    
  • Multiple referencesWhen the same field in a single page needs to be referenced multiple times in different positions of the template, and each reference may require different processing, assigning it to a variable will make it clearer and more efficient.

In summary, AnQi CMS'spageDetailTags provide a flexible way to display content. For simple, one-time content display needs, outputting directly without setting variable names can make your template code more concise and efficient.When dealing with content that requires deep processing or multiple references, using variable names in conjunction can provide greater control.Mastering these two methods will allow you to thrive in the content operation of Anqi CMS.


Frequently Asked Questions (FAQ)

1. Why does AnQi CMS allowpageDetailnot to set variable names for tags? What are the benefits of doing so?

AnQi CMS allowspageDetailTags not setting variable names is mainly to simplify template code and improve development efficiency.When you only need to retrieve and directly output a single page field (such as title, description, image link) to a specific position in HTML, you do not need to introduce an additional variable to store the data.This approach makes the code more concise and clear, especially suitable for those who do not process the data twice, only for simple "take and use" display scenarios.

2. Can you directly access when variable names are not set?pageDetailDo the output content use filters?

Sure. WhenpageDetailWhen outputting tags directly, you can immediately apply filters after them. For example, if you want to output a single page content directly and ensure that HTML is parsed, you can write it like this:{% pageDetail with name="Content" render=true|safe %}If you want to truncate a title that is output directly, you can do it like this:{% pageDetail with name="Title" %}|truncatechars:15Please note that for some complex operations, such as when you need to make conditional judgments based on output values or need to refer to the same processed value multiple times, it is clearer to assign it to a variable first before performing the operation.

3.pageDetailDirect outputContentWhat will happen to the field if it contains HTML tags?

By default, to prevent security issues such as cross-site scripting (XSS), the Anqi CMS template engine will processpageDetailDirect outputContentHTML tags in the field.Automatic escapingThis means that HTML tags will be displayed as plain text, rather than being parsed by the browser as actual HTML elements.If you are sure the content is safe and you want HTML to be parsed normally, be sure topageDetailAfter the label using|safefor example:{% pageDetail with name="Content" render=true|safe %}If the content is in Markdown format, remember to addrender=truethe parameter to ensure it is rendered into HTML before passing through|safeOutput.

Related articles

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

As an experienced website operation expert, I know that understanding the essence of template tags in a high-efficiency content management system like AnQiCMS is the key to exerting its powerful functions and building flexible pages.Today, let's delve into a common problem encountered when calling single-page details: What are the respective roles of '`variable name`' and '`field name`'?In the AnQi CMS template system, the `pageDetail` tag is specifically used to call up detailed information for a single page.

2025-11-07

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

Besides ID, which parameter can be used to specify the single page to be retrieved?

As a senior website operations expert, I am well aware that how to flexibly and efficiently locate and obtain specific content in a content management system is the key to improving operation efficiency and website SEO performance.AnQiCMS provides very practical mechanisms in single-page management, in addition to the most common way to specify a single page through ID, there are actually parameters that are more in line with the operational thinking that can be utilized.Today, let's delve deeply into this topic.

2025-11-07