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

As an experienced website operation expert, I know that in a high-efficiency content management system like AnQiCMS, mastering template tags is the key to improving operational efficiency and achieving personalized content display. Today, let's delve into a very practical tag -pageDetailIt can help us easily obtain and display the independent page content on the website.

Unveiling AnQiCMS'spageDetailTag: easily control the single page content display

In modern website operations, pages such as "About Us", "Contact Information", "Privacy Policy", and "Service Agreement" play a crucial role.They are not only a window for conveying core information to visitors and building trust, but also an indispensable part of search engine optimization (SEO).Aqiji CMS fully understands the importance of these pages and provides powerful and easy-to-usepageDetailTags, allowing content operators to manage and display these single-page contents flexibly without touching complex code.

pageDetailThe core function of the tag is to accurately obtain and output detailed data of the specified independent page. Imagine that your website has multiple independent pages, and you may need to display their titles, summaries, or full content in different template areas, at this timepageDetailWill be of use.

pageDetailBasic syntax of tags

pageDetailThe general syntax structure of the tag is very intuitive, it follows the style of the Django template engine and combines the Go language features of AnQiCMS, ensuring high performance and security:

{% pageDetail 变量名称 with name="字段名称" id="1" %}

This syntax may seem complex at first glance, but once we break it down, we find it very friendly.

  • {% pageDetail ... %}: This is the start of the tag, indicating that we are callingpageDetailFeature.
  • 变量名称(Optional): You can specify a temporary variable name for the data you obtain, such asmyPageIf omitted, the tag will directly output the content of the specified field.The benefit of assigning data to a variable is that you can refer to this variable multiple times in the subsequent part of the template, or perform more complex processing, such as in aifCheck if it exists in the judgment or combine it with other data to display.
  • with: This is a delimiter used to introduce subsequent parameters.
  • name="字段名称"This is a crucial parameter that determines which specific data field you need to retrieve from an independent page, such as the title, content, and links.
  • id="1"ortoken="about-us"These are used to specify which independent page you want to retrieve parameters for.

MasterpageDetailcore parameters

To accurately retrieve the single-page data you need,pageDetailThe label provides several key parameters that allow you to flexibly locate and extract information.

  1. Parameters to locate a specific page:idortoken

    When you need to accurately select a certain page from among many independent pages to display its details,idandtokenthe parameters become particularly important. They are the 'identity card' of the target page you specify.

    • idParameterThis is located by the numeric ID of an independent page. For example, if the "About Us" page in the back-end has an ID of5, then you can useid="5"Get its data. This method is very useful when you need to refer to a fixed ID page, such as displaying a specific page in the footer navigation.

      {# 获取ID为5的单页标题 #}
      <div>关于我们标题:{% pageDetail with name="Title" id="5" %}</div>
      
    • tokenParameter: Compared to numeric ID,tokenThe parameter allows you to locate through the page's "URL alias" (i.e., custom URL). For example, the URL alias for your "Contact Us" page is set tocontact-usthentoken="contact-us"It will be more readable and memorable. In AnQiCMS, setting meaningful custom URL aliases for single pages is not only good for SEO, but also makes template calls more semantic.

      {# 获取URL别名为"contact-us"的单页链接 #}
      <a href="{% pageDetail with name="Link" token="contact-us" %}">联系我们</a>
      

    In most cases, if you call in the current independent page templatepageDetailAnd not specifyidortokenthe tag will automatically retrieve the details of the current page. But if you need to reference a specific single page across pages, you must useidortokenSpecify clearly.

  2. Specify the parameters for getting data fields:name

    This ispageDetailThe core of the tag, which tells the tag which part of the page information you want to get.nameParameters support a variety of commonly used fields, covering all aspects of independent pages:

    • Id: The unique numeric identifier of the page.
    • Title: The title of the page, usually the content of the H1 tag.
    • LinkThe page's access link.
    • DescriptionA brief description of the page, often used for SEO meta descriptions or page summaries.
    • Content: The main content of the page, including all text, images, formats, and other content edited in the backend editor.
    • Logo: The main image or thumbnail large image of the page (if set).
    • ThumbThe thumbnail of the page (if set).
    • ImagesThe slide group image of the page (if multiple images are set, it will return an array of image URLs).

    For example, to get the title and content of a page:

    {# 获取指定ID页面的标题并赋值给pageTitle变量 #}
    {% pageDetail pageTitle with name="Title" id="10" %}
    <h1>{{ pageTitle }}</h1>
    
    {# 获取指定ID页面的内容并赋值给pageContent变量 #}
    {% pageDetail pageContent with name="Content" id="10" %}
    <div class="main-content">{{ pageContent|safe }}</div>
    

    Pay special attention hereContentThe call of the field. Since the page content usually contains HTML tags (such as paragraphs, images, links, etc.), in order to make the browser parse and render these HTML tags correctly and not treat them as plain text, you must use|safeFilter. Moreover, if your page content is written in a Markdown editor in the background, you can also addrender=trueParameter, let AnQiCMS automatically convert Markdown syntax to HTML before output to ensure the correct display of content.

    {# 渲染Markdown内容并使用|safe过滤器确保HTML正确解析 #}
    {% pageDetail pageContent with name="Content" id="10" render=true %}{{ pageContent|safe }}
    

    ForImagesfield, because it may contain multiple images, so it will return an array of image URLs. You need to combineforloop tags to iterate and display these images:

    {% pageDetail pageBannerImages with name="Images" id="10" %}
    {% if pageBannerImages %}
        <div class="page-slider">
            {% for imgUrl in pageBannerImages %}
                <img src="{{ imgUrl }}" alt="页面图片">
            {% endfor %}
        </div>
    {% endif %}
    
  3. Parameters under multi-site environment:siteId

    AnQiCMS supports multi-site management, which is very convenient for enterprises with multiple brands or sub-sites. If you are in a multi-site environment, you need to callfrom a non-current siteof a certain independent page data, can be usedsiteIdThe parameter is used to specify the site ID explicitly. Usually, if you only operate one site or call the data of the current site, this parameter does not need to be filled in.

    {# 获取ID为10的页面的标题,但它属于站点ID为2的站点 #}
    <div>其他站点页面标题:{% pageDetail with name="Title" id="10" siteId="2" %}</div>
    

Actual Application: Build a "About Us" page

Let's tie together with an example of a common "About Us" pagepageDetailTag Usage:

Suppose we have a URL alias namedabout-usThe "About Us" page, we need to display the company profile, detailed content, and possibly a corporate culture photo album on the page.

``twig <!DOCTYPE html>

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{# 设置页面标题 #}
<title>{% tdk