AnQiCMSpageDetaillabel'sidParameter: Flexible art that is not required

As an experienced website operation expert, I know in my daily work that the flexibility of the content management system template is important for improving operational efficiency and website performance.AnQiCMS (AnQiCMS) relies on its concise and efficient architecture, which is also reflected in the design of template tags.Today, let's delve into a common problem encountered in template creation:pageDetailin the labelidIs the parameter mandatory? The answer is:It is not always necessary, it demonstrates the intelligence and flexibility of AnQiCMS in content calls.

In the template design of AnQi CMS,pageDetailThe tag is specifically used to display detailed content of a single page (such as 'About Us', 'Contact Us', and other independent pages').The core value of this tag lies in its ability to accurately capture and present the title, description, content, images, and other rich information of a specific single page according to your needs.

Intelligent default: when you do not need to specify an ID

AnQiCMS is designingpageDetailWhen labeling, full consideration is given to the most common usage scenarios. When you are already on a single page detail page (for example, you are editing or previewing the "About Us" page created by the backend, whose URL might be/page/about-us.htmlInvoke directlypageDetailTags to get the information of the current page, the system will default recognize the ID of the current page. This means, you can completely omitidParameters, AnQiCMS will automatically extract the data of the current single page you are browsing.

For example, in your "About Us" single page templatepage/detail.html(or customizedpage/about.htmlIn the brackets, if you want to display the title and content of this page, you can simply write:

<h1>{% pageDetail with name="Title" %}</h1>
<div class="page-content">{% pageDetail with name="Content" %}</div>

Here, you do not need to explicitly tellpageDetailLabel 'Give me the single page with ID X' because it already knows you want to be on this page.This design greatly simplifies the template code, improves development efficiency, and reduces the possibility of errors.

Accurate positioning: when it is necessary to provide explicitlyidortoken

However, this default intelligent behavior is not suitable for all scenarios. If you wish tonon-single-pageor on some single-pagereference content from other single pagesWhen you need to explicitly tellpageDetailThe tag you want to get the data of which single page. At this time,idortokenThe parameters come into play.

  • Useidparameters: idThe parameter is used to specify the numeric ID of a single page. You can use it directly when you are clear about the unique numeric identifier of the target single page.For example, you want to display a part of the single page "Company News" (assuming its ID is 5) in a certain block on the website homepage, you can call it like this:

    <a href="{% pageDetail with name='Link' id='5' %}">
        <h2>{% pageDetail with name="Title" id="5" %}</h2>
    </a>
    <p>{% pageDetail with name="Description" id="5" %}</p>
    
  • Usetokenparameters: tokenThe parameter is used to specify the URL alias for a single page. Compared to numeric IDs, URL aliases are usually more readable and memorable, and also more SEO-friendly.For example, the URL alias for the "About Us" page might beabout-usThen you can call it like this:

    <section id="contact-info">
        <h3>联系我们</h3>
        <div>地址:{% pageDetail with name="Content" token="contact-us" %}</div>
    </section>
    

    This method remains stable in the background page URL alias, and it is especially convenient when you want to refer to the page in a more intuitive way.

Cross-site considerations:siteIdAdvanced applications

exceptidandtokenYou may also noticepageDetailThere is also a labelsiteIdParameters. This is usually used for multi-site management scenarios in AnQiCMS.If you are operating multiple sites and you want to call a specific single-page data under another site in a template on one site, thensiteIdThe parameter becomes indispensable. It allows you to cross the boundaries of the site, achieving flexible sharing and calling of content.Of course, for most single-site operators, this parameter can be ignored.

**Practice and flexible application

In summary,pageDetailin the labelidWhether parameters must be provided depends entirely on your use scenario and objectives.

  • When obtaining the content of the target single-page detail page,idthe parameter is not required.you can rely on the intelligent default behavior of AnQiCMS.
  • When on other pages or when referencing specific single-page content,idortokenthe parameter is your precise targeting tool.Prioritize usingtoken, as it is easier to understand and maintain, and is also more SEO-friendly.

The template tag design concept of Anqi CMS lies in providing the greatest flexibility, allowing you to write concise, efficient, or precise control code according to your actual needs.Understanding the semantics and usage scenarios of these parameters will help you better master AnQiCMS and create a powerful, user-friendly website.


Frequently Asked Questions (FAQ)

Q1:pageDetailin the labelidandtokenWhat are the differences? Which one should I use first?

A1:idA parameter is a unique identifier for a single page, usually automatically allocated by the system.tokenA parameter is the URL alias of a single page, usually set by the user in the background, more semantic and readable.When referencing a non-current single-page template, you can choose either one.Suggest using first prioritytokenBecause it is more intuitive in the template and it does not need to modify the template code when the page ID changes in the database (although it is not common), usingtokenand it is also SEO-friendly.

Q2: If I use a tag in a non-single-page template,pageDetailbut did not provideidortokenWhat will happen?

A2: If you are not on a single page detail page (i.e., the route of the current page does not point to a specific single page), but you called it in the templatepageDetailand did not provideidortokenparameter,pageDetailThe label cannot identify the single-page ID in the context. This usually leads to the label returning an empty value, or it may cause template rendering errors under some strict template configurations.Therefore, calling in non-single-page templatepageDetailEnsure that it is clearly providedidortoken.

Q3:pageDetailandpageListWhat are the uses of each tag, and how should I choose?

A3:pageDetailTags are used to retrieve and displaySpecific singleDetailed information on a single page, emphasizing "details".pageListTags are used to retrieveMultiple single pagesa list, usually combined with loop tags such asfor)To display all or part of a single page (for example, list all of our about us subpages at the bottom of the website). If you need to display the full content of the "About Us" page, usepageDetail; If you want to list all the single-page titles and links of the 'help document' type in the navigation or sidebar, you should usepageList.