How to use AnQiCMS to customize the display layout of the article detail page?

Calendar 👁️ 69

AnQiCMS provides a very flexible and powerful content management system, allowing us to easily customize the display layout of article detail pages.In order to enhance user experience, optimize SEO, or better showcase the brand characteristics, AnQiCMS can help us achieve these goals through its intuitive template system and rich tag functions.

How to operate specifically? We can delve into it step by step from the following aspects.

1. Understand the template mechanism of AnQiCMS

Firstly, we need to understand how AnQiCMS identifies and renders the article detail page. All template files are stored in/templateUnder the directory, and static resources (such as CSS, JS, images) are located/public/static/Directory. AnQiCMS uses a syntax similar to Django template engine, using double curly braces{{变量}}To output variables, use single curly braces and percent signs{% 标签 %}To handle conditional judgment, loop control, and other logic.

AnQiCMS will look for template files according to a certain priority when rendering article detail pages:

  • Default article detail template:All article detail pages usually use/template/{你的模板目录}/{模型table}/detail.htmlas the default template. For example, if you are using the "article model", the default template path isarticle/detail.html.
  • customized for a specific article ID:If you need to design a unique layout for a special article (such as an article with ID 10), you can create a namedarticle/detail-10.htmlThe template file. The system will prioritize using this more specific template.
  • Customize through the backend settings:AnQiCMS provides a more flexible way. When publishing or editing articles, you can find the 'Document Template' field in 'Other Parameters'.Here, you can directly enter a custom template filename (such asmy_special_article.html)。The system will look for and use this file in/template/{你的模板目录}/the directory.
  • Customize through category settings:Further, you can also specify a unified detail page template for all articles under a certain category.In the document classification management interface, when editing categories, you can set the document template in the 'Other Parameters', and even choose whether to apply it to subcategories.This category and all subcategories' articles will be displayed according to this template.

These flexible template specification methods provide us with great freedom to customize the article detail page.

2. Backend configuration: build content and data

Before starting to write template code, an important step is to prepare the required content structure and data in the AnQiCMS backend.

  • Flexible content model:One of the core highlights of AnQiCMS is the flexible content model.In addition to the default article and product models of the system, we can customize new content models according to business needs and add exclusive "custom fields" to each model.For example, if we add fields such as 'article author' and 'article source' to the article model, then the data of these fields can be called and displayed on the article detail page, greatly enriching the content dimension.
  • Fill in the content when publishing the document:When adding a document or editing an existing document, we need to make full use of these fields.For example, in addition to the usual article title, abstract, and content, we can upload thumbnails, set related Tag tags, fill in custom URLs, and especially pay attention to the "document template" field mentioned earlier, where you can select or fill in the custom template path prepared for the current article.
  • Document template settings in category management:As mentioned before, if you want all articles under a certain category to use a specific detail page layout, you can edit the category in the 'Document Category', then specify the 'Document Template' in the 'Other Parameters', and choose whether to apply it to subcategories.This is very effective for maintaining a consistent style in specific content blocks (such as news, cases, blogs, etc.)

3. Front-end template writing: Implement beautiful layout

Once the background data and template path are ready, we can start writing the front-end template code.AnQiCMS's template system is based on the powerful capabilities of Go language and is easy to learn.

  • Structuring of the template: Inheritance and inclusionIn general, a website has a common header, footer, and sidebar. We can make use ofextendsandincludetags to build modular templates:

    • {% extends 'base.html' %}Inbase.htmlDefine the basic framework of the website (such as HTML structure, introducing CSS/JS, common header and footer), and through{% block content %}Tags define areas that can be overwritten. The article detail page template can inherit.base.htmlOnly focus oncontentthe layout of the part.
    • {% include 'partial/header.html' %}: For some small reusable code snippets (such as navigation bars, contact information), you can useincludetag introduction to keep the code neat
  • to call the core content of the articleIn the article detail page template, the core issue is how to obtain and display the data of the current article.archiveDetailTags are our main tools: "`twig"

    <h1>{% archiveDetail with name="Title" %}</h1> {# 显示文章标题 #}
    <div class="article-meta">
        <span class="category">分类:<a href="{% categoryDetail with name='Link' %}">{% categoryDetail with name='Title' %}</a></span>
        <span class="pub-date">发布时间:{% archiveDetail with name="CreatedTime" format="2006-01-02 15:04" %}</span>
        <span class="views">阅读量:{% archiveDetail with name="Views" %}</span>
        <div class="tags">
            {% tagList tags with itemId=archive.Id limit="10" %} {# 调用当前文章的标签 #}
            {% for item in tags %}
                <a href="{{item.Link}}">{{item.Title}}</a>
            {% endfor %}
            {% endtagList %}
        </div>
    </div>
    <div class="article-content">
        {%- archiveDetail articleContent with name="Content" %}
        {{ articleContent|safe }} {# 输出文章内容,|safe 确保HTML标签被正确解析 #}
    </div>
    {# 如果文章内容是Markdown格式,且需要在前端渲染,可以使用render过滤器 #}
    {# {{- archiveDetail articleMarkdownContent with name="Content" render=true %}}
       {{ articleMarkdownContent|safe
    

Related articles

How to display or customize the error pages (such as 404, 500) and shutdown notifications of a website?

In the operation of the website, visitors may encounter pages that cannot be found for various reasons or temporary issues with the server, and may even be unable to access the website during maintenance and upgrades.In these situations, a well-designed error page (such as 404, 500) and a friendly shutdown prompt can not only greatly improve user experience but also maintain the professional image of the website to a certain extent and search engine optimization (SEO).AnQi CMS is an efficient content management system that provides a flexible way to display and customize these important pages.###

2025-11-09

How to display the list of dynamic Banner images configured in the website?

The website's banner area, like a dynamic promotional window, its visual appeal and content delivery efficiency directly affect the first impression of visitors to the website.A well-designed Banner that can quickly capture the user's attention and effectively showcase the brand image, latest activities, or core products.In AnQiCMS (AnQi CMS), by utilizing its powerful content management features, you can easily configure and display a dynamic banner image list, keeping your website fresh and attractive.###

2025-11-09

How to add hreflang tags in templates to support multi-language SEO?

With the increasing trend of globalization, many websites are facing the challenge of providing content to users of different languages or regions.To ensure that your multilingual website performs well in search engines and accurately guides users to their preferred language version, adding the `hreflang` tag is crucial.AnQiCMS (AnQiCMS) is an enterprise-level content management system that deeply supports multilingualism and provides a convenient way to implement this feature in templates.### Understand the role of the hreflang tag `hreflang`

2025-11-09

How to display multi-language switch options for the current site?

How to easily add multilingual switching options to a website in AnQi CMS?With the continuous deepening of globalization trends, many enterprises and content operators find that having a website that supports multilingual is crucial for expanding the market and serving users in different regions.AnQi CMS understands this need, therefore it has built-in powerful multilingual support functions, allowing you to easily manage and display content in different languages. After your website content is prepared in multiple languages, the next step naturally is to provide visitors with an intuitive language switcher.This can not only improve the user experience

2025-11-09

Does AnQiCMS support displaying different detail page styles based on different content models?

In website operation, we often encounter such needs: different types of content, even on the same website, also need to have completely different display styles.For example, a product detail page of an e-commerce website needs to highlight product images, prices, inventory information, etc., while the blog article detail page may focus more on the reading experience, author information, and publication date.This ability to customize the style of detail pages based on content type (also known as content model) is crucial for improving user experience and content professionalism.Then, while using AnQiCMS

2025-11-09

How to display only articles of specific categories in the article list?

When managing website content in Anqi CMS, we often need to flexibly control the display of article lists, for example, only displaying articles under specific categories on a certain page.This not only helps to organize the content of the website accurately, but also greatly improves the browsing experience of visitors, helping them find the information they are interested in faster.AnQi CMS provides powerful template tag features, making this requirement simple and intuitive.The core of achieving this goal lies in the `archiveList` template tag of Anqi CMS.This tag is used to obtain the 'universal key' for the article list from the database

2025-11-09

How to configure AnQiCMS to enable lazy loading of images on the page?

In today's rich network world, the speed of website loading is of great importance to user experience and search engine optimization (SEO).Especially when a page contains a large number of images, how to effectively manage the loading of these images, avoid the lag caused by loading all resources at once, has become a focus of many website operators.The Lazy Load (Lazy Load) technology is the tool to solve this problem, it allows images to be loaded only when the user is about to see them, thus significantly improving page performance.AnQiCMS as a high-performance content management system

2025-11-09

How to use template tags to dynamically display the associated Tag list in article content?

How can we make users see the related keywords or topic list in an article at a glance while browsing, so as to guide them to discover more interesting content and thus improve user experience and website stickiness, which is an important link.AnQiCMS (AnQiCMS) provides powerful template tag features, allowing you to easily display related Tag lists dynamically in article content, which is both beautiful and practical.**Understanding the Tag Function of AnQi CMS** Tags in AnQi CMS are not just simple classifications of articles

2025-11-09