As a senior CMS website operation personnel of an information security company, I know that correctly calling content links in the template is crucial for the user experience of the website and SEO.The single page is a key part that carries static information such as "About Us" and "Contact Information", and the accurate calling of its links is an indispensable part of daily operation.

I will elaborate in detail on how to correctly call the single-page link in the AnQi CMS template.

Understand the single-page link in the AnQi CMS.

In Anqi CMS, a single page (also known as "page") exists independently of content models such as articles, products, and the like.Each single page is created in the background with a unique identifier (ID) and an optional "custom URL" (URL alias).This information is the basis for correctly calling the link in the template.The template engine of AnQi CMS is based on Django syntax, using double curly braces{{变量}}Output variable values and support data retrieval through specific tags.

Call the link to a specific single page.

When you need to reference a single-page link at a fixed position in a template, such as in the website navigation, footer, or sidebar, you can useSpecific.pageDetailThe tag allows you to accurately obtain the detailed information of a single page by its ID or its URL alias, including its link.

UsepageDetailWhen tagging, you can specifyidortokenPass parameters to locate the target single-page, and throughname="Link"Pass parameters to extract its URL.

Here is an example of calling a specific single-page link:

{# 假设我们已知“关于我们”页面的ID是1 #}
<a href="{% pageDetail with name='Link' id='1' %}">关于我们</a>

{# 假设“联系我们”页面的URL别名(token)是“contact-us” #}
<a href="{% pageDetail with name='Link' token='contact-us' %}">联系我们</a>

{# 您也可以将链接赋值给一个变量,再使用 #}
{% pageDetail aboutUsLink with name='Link' id='1' %}
<a href="{{ aboutUsLink }}">关于我们</a>

In these examples,name='Link'Make it clear to the Anqi CMS template engine that we want to retrieve the external link of this single page.The system will automatically generate a complete and accessible URL based on the "custom URL" in the background and the website's pseudo-static rules.

List of links to batch call single pages

If you need to display multiple single-page links in a loop, such as in a sitemap or a 'Featured Pages' list,pageListtags will be your ideal choice.pageListThe tag will return an array object containing all single page information, you can traverse it byforand get the link of each single page.

This is an example of calling a batch of single page links

<nav class="footer-pages-nav">
    <ul>
        {% pageList pages %}
            {% for item in pages %}
                {# item.Link 会输出当前单页面的链接 #}
                <li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
            {% endfor %}
        {% endpageList %}
    </ul>
</nav>

In this example,pageListAll available single pages were retrieved,for item in pagesThe structure then processes each single page in order.{{ item.Link }}The variable will output the URL of the current single page in each loop, while{{ item.Title }}it will output the page title, making it convenient for you to build a dynamic page list.

an important consideration when calling the template

When calling single-page links in templates, there are several practices and backend configurations that you need to pay attention to in order to ensure the accuracy of the links and the overall performance of the website:

first, Custom URL settingsDetermines the link form of a single page. In the "Page Management" of AnQi CMS backend, each single page can be set to have a "Custom URL".This setting will directly affectpageDetailandpageListLabel outputLinkValue, it is recommended that you set a concise and meaningful custom URL for important pages, which is very beneficial for SEO optimization and user memory.

secondly,The use of single-page template filesIt is also a key point. Anqi CMS allows you to specify custom templates for single pages, such aspage/detail.htmlAs the default template, orpage/{单页ID}.htmlEven manually specified in the backgroundpage/about.html.LinkThe tag outputs the URL to access these pages, not the path to the template file itself.

Finally, if you are operating AnQi CMS in a multi-site environment and need to refer to single-page links from other sites,pageDetailandpageListtags are supportedsiteIdparameter. ThroughsiteIdYou can explicitly specify which site to fetch single-page data from, thereby realizing cross-site link calls.

By using the above method, you can flexibly and efficiently call single-page links in the Anqi CMS template, whether it is a precise reference to a single page or a list display of multiple pages, it can be easily realized, thereby enhancing the overall navigation and user experience of the website.


Frequently Asked Questions (FAQ)

Q1: What should I do to troubleshoot the issue of my single-page link not displaying correctly in the template?

A1: If the single page link is displayed incorrectly, please first check if the "Custom URL" setting of the single page in the "Page Management" section of the Anqie CMS backend meets your expectations, as this is the basis for generating links.Next, go to the "Function Management" under the "URL Rewrite Rule" page, confirm whether the URL rewrite rule of the single page is correctly configured and effective.Incorrect pseudo-static rules may cause links to be incorrectly parsed.

Q2: Can I display a single page link with a specific ID or under certain conditions within a loop?

A2: Absolutely. When usingpageListAfter getting the list of single-page tags, you canforcombine within the loopifFilter tags logically. For example, you can write the code to display only single-page links with ID 5 and ID 10:

{% pageList pages %}
    {% for item in pages %}
        {% if item.Id == 5 or item.Id == 10 %}
            <li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
        {% endif %}
    {% endfor %}
{% endpageList %}

Q3: How to insert images or videos into a single page and call these media contents in the template?

A3: The main content of a single page (ContentField) is edited through the rich text editor in the background. You can directly insert images or videos in the editor. If the page is configured with media resources such as "Banner image" or "thumbnail", you can use them in the template.pageDetailLabels to call them. For example, `