In AnQiCMS, single pages are a very practical part of the website structure, and they are usually used to display static content such as 'About Us', 'Contact Information', etc.As a content operator, you may often need to retrieve and display the content and titles of specific single pages at different locations on the website.AnQiCMS provides intuitive and powerful template tags, making this process very simple.

Understanding the single page in AnQiCMS

One of AnQiCMS's design philosophies is the high degree of customizability of content.The single page is managed in the "Page Resources" module on the backend. You can set a separate title, content, keywords, description, even a custom URL, and a dedicated template file for each single page.This flexibility allows a single page to not only carry rich information but also perfectly integrate with the overall design style of the website.

In the AnQiCMS template system, you will find that it uses a syntax similar to the Django template engine, using double curly braces{{变量}}Output variables, while conditional judgments and loop controls are used{% 标签 %}Structure. All template files are recommended to use UTF-8 encoding to avoid garbled characters.

The core tool to retrieve the content and title of a specific single page:pageDetailTag

To retrieve and display the content and title of a specific single page, we mainly use:pageDetailThis template tag. This tag is specifically designed to extract detailed information from a single page.

pageDetailThe basic usage of tags is:{% pageDetail 变量名称 with name="字段名称" id="页面ID" %}.

Here变量名称is an optional parameter, if you set it, you can call the data obtained through this variable. If omitted变量名称,pageDetailthe label will output the specifiednamefield value.nameThe parameter is used to specify the specific field you want to retrieve, whileidortokenThe parameter is used to specify which single page.

To get the title of a single page

To display the title of a single page, you need tonameSpecify in the parameterTitleFor example, if you want to get the title of the single page you are currently visiting, you can write it like this:

<h1>{% pageDetail with name="Title" %}</h1>

If you want to get the title of a single page with ID 10, regardless of which page you are currently on, you can do it like this:

<p>这是ID为10的单页面标题:{% pageDetail with name="Title" id="10" %}</p>

You can also specify a single page using its URL alias, i.e.tokenSpecify a page. This is very useful when you want to reference a page with a more descriptive URL. For example, if your "About Us" page's URL alias is set toabout-usYou can get the title like this:

<p>关于我们页面的标题是:{% pageDetail with name="Title" token="about-us" %}</p>

Get the content of a single page

Getting the main content of a single page is also simple, just need tonamethe parameter toContentIt is. It should be noted that the content of a single page usually contains HTML tags, in order for the browser to parse and display these formats correctly, you need to cooperate with|safefilter usage.|safeThe filter tells the template engine that this part of the content is safe HTML and does not need to be escaped.

If you have enabled the Markdown editor to edit single-page content in the background and want to render it as HTML on the front end, you can add in theContentfield.render=trueparameters:

<div>
    {% pageDetail pageContent with name="Content" render=true %}
    {{ pageContent|safe }}
</div>

If your content is not Markdown or you do not want Markdown renderingrenderThe parameter can be omitted.

This is an example of fetching the current single page content:

<section class="page-content">
    {% pageDetail contentData with name="Content" %}
    {{ contentData|safe }}
</section>

Actual application example: Display the title and introduction of the "Contact Us" single page in the sidebar

Suppose you have a 'Contact Us' single page with ID 5, and you want to display its title and part of the content (summary) in the website sidebar.

<aside class="sidebar-contact">
    <h2>{% pageDetail with name="Title" id="5" %}</h2>
    <p>{% pageDetail with name="Description" id="5" %}</p>
    <a href="{% pageDetail with name="Link" id="5" %}" class="btn-more">了解更多</a>
</aside>

In this example, we specifyid="5"to obtain the title of a specific single page (Title), description (Description) and the links(Link), and display them in the sidebar.

Tips and **Practice

  1. Make good use of|safeFilterWhen you display any content that may contain HTML (such as single-page content, article content), be sure to use|safeFilter, otherwise HTML tags may be displayed as plain text.
  2. Custom URL alias improves SEO: Set meaningful custom URL aliases for single-page pages (tokenIt not only facilitates memory and reference, but also helps to improve search engine optimization.
  3. Naming conventions of template files:AnQiCMS supports custom templates for specific single pages. For example, you can createtemplate/your_template_folder/page/about.htmlFile, and specify the use of this template for the "About Us" page in the "Page Management" section of the background. This can achieve more detailed page layout control.
  4. Background managementIn the "Page Resources" -> "Page Management" section, you can conveniently create, edit, and manage all single pages.Here the "page name

By flexible applicationpageDetailTags and related parameters, you will be able to easily handle the single-page content display of AnQiCMS, whether it is building a standard corporate website or a complex marketing site, you will be able to handle it with ease.

Frequently Asked Questions (FAQ)

1. Why is my single-page content displaying raw HTML code instead of formatted content?This is likely because you did not use|safeFilter.The AnQiCMS template engine, for security reasons, defaults to escaping all output content to prevent XSS attacks.|safeFilter, for example{{ pageContent|safe }}.

2. How do I reference and display the title of a specific single page in the sidebar of the article detail page?You can use in the template of the article detail page,pageDetailLabel and specify a single pageidortokenFor example, if you want to display the title of the 'Contact Us' page with ID 5, you can write it like this:<h3>{% pageDetail with name="Title" id="5" %}</h3>This will display the title of the specified single page regardless of the current article.

3. If I want to use a completely different layout for a specific single page instead of the default onepage/detail.htmlHow should I operate?AnQiCMS supports custom templates for each single page. You can create a new template file in your template folder (for exampletemplate/default), such aspage/custom-about.htmlThen, edit the single page in the background "Page Management", find the "Single Page Template" setting, and fill incustom-about.htmlAnd so, the single page will use the custom layout you created.