How to customize the display layout and elements of the AnQi CMS article detail page?

Calendar 👁️ 66

In AnQi CMS, managing and displaying content is a core function, and the article detail page, as an important interface for users to obtain information and interact with the website, is directly affected by the layout and design of elements, which has a direct impact on user experience and information communication efficiency.AnQi CMS provides high flexibility, allowing users to deeply customize the display of article detail pages according to their own needs.

To customize the article detail page, you first need to understand the Anqi CMS template system. It uses syntax similar to the Django template engine, and template files are usually named with.htmlwith the suffix and uniformly stored in the root directory of the system/templatefolder. Static resources such as styles, JavaScript scripts, and images related to the template are located/public/static/Directory. This separation design makes it possible for content and presentation layer to be managed independently, which is convenient for developers to carry out secondary development and personalized adjustment.

Confirm and create your article detail page template file.

The AnqiCMS template follows certain naming conventions. The default template path for article detail pages is{模型table}/detail.html. Here,{模型table}It is usually the table name defined when the content model is set up in the background, for example, if the table name of your article model isarticle, then the default article detail page template isarticle/detail.html.

A more flexible way is to specify a dedicated template for specific articles or articles in a specific category. The system supports naming custom templates by document ID or category ID:

  • Named by document ID: {模型table}/detail-{文档ID}.htmlFor example, if you want to create a unique detail page for an article with ID 10, you can name itarticle/detail-10.html.
  • Specify through categories:You can specify a unified document template for all articles under this category in the category settings, for examplemycategory_detail.html.

This means you can first copy and modify the default one{模型table}/detail.htmlThe file starts and then save it as the file with the above agreed name for customization.

Specify a custom template in the background.

After creating a custom template file, you still need to associate it in the Anq CMS backend so that the system knows which template to use to render specific articles:

  1. Specify when publishing/editing a document:In the 'Content Management' module, when you 'publish documents' or 'edit documents', in the 'Other Parameters' section, you will find an option named 'Document Template'. Here you can enter your custom template filename (for examplemy_custom_article.html)。The system will prioritize the use of the template specified here.
  2. Specified when setting categories:In the "Content Management" module under "Document Category", when editing a category, there are also two options, "Category Template" and "Document Template", in the "Other Parameters".The "Category Template" controls the layout of the category list page, while the "Document Template" controls the layout of the detail pages for all articles in the category.If you want all articles under a category to use the same custom layout, you can specify it here.

Invoke core data and control display elements

In the article detail page template file, you can use the rich tags provided by AnQi CMS to call and display data, as well as control the layout:

  • Get the article's own data:Use{% archiveDetail %}Tag. This is the most core tag on the detail page, which allows you to obtain all fields of the article such as title, content, link, description, cover image, and so on.

    • For example, to display the article title:<h1>{% archiveDetail with name="Title" %}</h1>.
    • Show article content:<div>{% archiveDetail with name="Content" render=true lazy="data-src" %}{{archiveContent|safe}}</div>. Here,render=trueEspecially useful when turning on the Markdown editor, it will render Markdown content into HTML;lazy="data-src"Then it is convenient to integrate lazy loading of images;|safeThe filter is used to prevent HTML tags in the content from being escaped.
    • You can accessname="字段名称"To get a single field, for examplename="Logo"Get the cover main image,name="Images"Get the group image.
  • Display custom additional fields:If you add custom fields (such as "author", "source") in the background of the content model, you can use{% archiveParams %}tags to call.

    • For example, loop to display all custom fields:
      
      {% archiveParams params %}
          {% for item in params %}
              <p>{{item.Name}}:{{item.Value}}</p>
          {% endfor %}
      {% endarchiveParams %}
      
    • Or call it directly by field name:<div>作者:{% archiveDetail with name="author" %}</div>.
  • Call category information:Use{% categoryDetail %}Tags, which can obtain the name, link, description, etc. of the article category.

    • For example:所属分类:<a href="{% categoryDetail with name='Link' %}">{% categoryDetail with name='Title' %}</a>.
  • Display related tags: {% tagList tags %}Tags can retrieve all tags associated with the current article.

    • Through a loop, you can display the links and names of these tags, for example:
      
      {% tagList tags %}
          {% for tag in tags %}
              <a href="{{tag.Link}}">{{tag.Title}}</a>
          {% endfor %}
      {% endtagList %}
      
  • Navigate to the previous/next article: {% prevArchive %}and{% nextArchive %}Tags can conveniently add navigation links at the bottom of the article detail page.

    • For example:
      
      {% prevArchive prev %}
          {% if prev %}<a href="{{prev.Link}}">上一篇:{{prev.Title}}</a>{% else %}没有了{% endif %}
      {% endprevArchive %}
      
  • Display related article list:Use in the same way{% archiveList %}Tags, set throughtype="related"to retrieve other related articles for the current article.

    • For example:
      
      {% archiveList relatedArchives with type="related" limit="5" %}
          {% for item in relatedArchives %}
              <li><a href="{{item.Link}}">{{item.Title}}</a></li>
          {% endfor %}
      {% endarchiveList %}
      
  • Breadcrumbs navigation: {% breadcrumb %}Used to generate the navigation path of the website, helping users understand their current location.

    • For example:
      
      {% breadcrumb crumbs %}
          {% for item in crumbs %}
              <span><a href="{{item.Link}}">{{item.Name}}</a></span>{% if not forloop.Last %} > {% endif %}
          {% endfor %}
      {% endbreadcrumb %}
      
  • Integrated comment function: {% commentList %}Used to display the comment list of the article, you can also combine{% pagination %}tags to implement pagination display.

    • Don't forget to add in the comment formcaptcha_idandcaptchathe corresponding JavaScript code to support captcha functionality to prevent spam comments.
  • Structure and logical control:

    • {% include "partial/header.html" %}: Used to introduce reusable template fragments, such as headers and footers.
    • {% extends "base.html" %}: Implement template inheritance, you can define a basic skeleton template and then overwrite specific content blocks in the detail page template ({% block content %})
    • {% if 条件 %}/{% for 循环 %}Perform conditional judgment and loop traversal to control the display logic of content.

Management of layout and style files.

In addition to calling data from template files, the final layout and visual effects of the article detail page are achieved through the combination of HTML structure and CSS styles. You can place custom CSS and JS files in/public/static/你的模板目录/css/and/public/static/你的模板目录/js/In the directory, then use it in the template{% system with name="TemplateUrl" %}Use the tag to get the static file address of the template and refer to them. For example:

<link href="{% system with name="TemplateUrl" %}/css/custom.css" rel="stylesheet">

By these tags and flexible file management methods, you can completely create a detailed page of articles that meet specific content display requirements, whether it is a simple blog article, a product introduction with pictures and texts, or a complex case display page, all of which can be easily realized through AnQi CMS.


Frequently Asked Questions (FAQ)

How to set different layouts for article detail pages of different content models (such as articles, products)?You can define multiple content models in the Anqi CMS backend, such as the "Article" model and the "Product" model.Then, create an independent detail page template file for each content model.According to the AnQi CMS template naming convention, you can createarticle/detail.htmlAs the default detail page for the article model, as well asproduct/detail.htmlAs the default detail page of the product model. In this way, the content of different models will automatically apply the corresponding template layout.You can also specify a more specific template file for a single content item when publishing or editing a single article/product in the 'Document Template' option.

2. How do I display custom fields on the article detail page?If you add a custom field, such asauthor(author), andsource(Source), then in the article detail page template, these fields can be displayed in two ways: a.Call directly: <div>作者:{% archiveDetail with name="author" %}</div>. b.Loop traversal:If you want to display all custom fields, you can use{% archiveParams params %}{% for item in params %}<p>{{item.Name}}:{{item.Value}}</p>{% endfor %}{% endarchiveParams %}This method is particularly suitable for scenarios where the number of fields is not fixed or a uniform display format is required.

3. Why didn't my custom template file work on the website front-end?There are several common reasons that may cause a custom template not to work: a.Template file path or naming error:Please check if your template file is located in/template/你的模板主题目录/and the naming conforms to the Anqi CMS conventions (for example{模型table}/detail.htmlormy_custom_article.html). b.The backend did not specify a template:Make sure you have correctly selected or filled in the name of your custom template file on the article publishing/editing page, or the settings page for the corresponding category. c.The system cache has not been updated:Click on 'Clear Cache' in the background 'Update Cache' feature. d.Browser Caching:Try clearing the browser cache or accessing in incognito mode, as the browser may cache old page resources.

Related articles

How to flexibly configure the display of "Built-in links", "Category page links", and "External links" in the website navigation?

Website navigation, just like a map for users to explore your website, a clear and efficient navigation can greatly enhance the user experience and help visitors quickly find the information they need.In AnQiCMS, the website navigation configuration provides very high flexibility, allowing you to combine 'built-in links', 'category page links', and 'external links' ingeniously according to your actual needs, and make fine-grained settings. ### Diverse navigation location and hierarchy management In AnQiCMS, you do not have to stick to a fixed navigation menu.You can access the 'Navigation Category Management' feature

2025-11-08

How does image processing in content settings (Webp, large image compression) affect page loading speed and image display quality?

In website operation, images are undoubtedly the key elements that attract users and enrich content.High-quality images can greatly enhance the attractiveness of a page, whether it is for product display, article illustrations, or brand image.However, the size of image files is often a major culprit in slowing down website loading speed.Fortunately, AnQiCMS (AnQiCMS) provides powerful image processing functions in the content settings, such as WebP format conversion and automatic compression of large images, helping us cleverly balance image quality and page loading speed, thereby enhancing the overall user experience and SEO performance.###

2025-11-08

How to optimize search engine crawling and user experience with static rules (such as URL structure)?

In website operation, the URL plays a vital role.A well-designed URL can not only help search engines better understand and crawl the website content, but also significantly improve the user experience.AnQiCMS (AnQiCMS) understands this point, therefore, it has integrated flexible and powerful pseudo-static rules and 301 redirect management functions into its system, allowing website administrators to easily build URL structures that are friendly to both search engines and users. ### Static rules: Why are they so important?Imagine that

2025-11-08

How does the 'recommended attribute' of a document affect the call and display priority of content on the front end when it is published?

When using Anq CMS to manage website content, we often need to highlight certain important articles or products to make them easier for visitors to find.This is when the "recommended attribute" of content publishing comes into play.It is not a complex backend setting, but rather a very intuitive option that can be seen on the 'Add Document' interface every time we publish or edit a document. It is an important tool for effectively managing content display and call priority.

2025-11-08

How to accurately retrieve and display a specific article list based on category ID?

In a content management system, effectively organizing and displaying content is crucial for improving user experience and website SEO performance.AnQi CMS with its flexible and powerful template engine allows you to easily implement the requirement of fetching and displaying a list of articles based on a specific category ID.Whether it is to build a special page, category archive, or simply to display the latest content of a specific column on the homepage, Anqi CMS can provide intuitive and efficient solutions.This article will deeply explore how to utilize the template tag feature of Anqi CMS, especially the `archiveList` tag, to accurately achieve this goal

2025-11-08

How does Anqi CMS implement seamless language switching and display of multilingual content on the front-end page?

Today, with the deepening of globalization, website content that can reach users of different languages has become a key factor in enterprises expanding the market and enhancing brand influence.AnQiCMS (AnQiCMS) is well aware of this need, and from the very beginning of system design, it has made multilingual support one of its core features, aiming to help users easily switch and display content seamlessly on the front-end page.How does Anqi CMS help us build and manage multilingual websites and allow visitors to switch between different language versions smoothly?

2025-11-08

How to use the recommendation attribute (Flag) of AnQi CMS to display featured content on the homepage or special page?

AnQi CMS provides an efficient way to manage and highlight important content on your website, that is, through the "recommended attribute" (Flag).This feature allows you to easily display carefully selected content on the homepage, special pages, or other key positions, thereby guiding visitors' attention and enhancing the interactivity and information transmission efficiency of the website. ### Recommended Attribute Settings: The First Step of Content Selection In the AnQi CMS backend, the starting point of content management is to publish or edit documents.When you are ready with high-quality content, you hope it will stand out at a key position on the website

2025-11-08

How to customize the content model field and flexibly call it to display its content in the template?

AnQiCMS is one of the core strengths in content management, with its flexible and customizable content model.This allows us to no longer be limited by a fixed content structure, enabling us to create personalized content types that meet the actual operational needs of the website.No matter if you are publishing technical articles, showcasing product details, or managing event information, custom content model fields can help you accurately construct the content structure you need and ultimately flexibly display it on the website front end.

2025-11-08