Optimize the AnQiCMS article detail page long content reading experience:wordwrapEfficient application of filters

In website operation, we often need to publish long-form content containing a large amount of text, such as in-depth reports, tutorials, or detailed product introductions.This content is rich in information and is the key to attracting and retaining readers, but if the layout is not good, especially in a multi-device environment, the long line width can easily make readers feel tired when reading, and even lead them to give up reading halfway.In AnQiCMS, we can cleverly utilize the powerful template system provided bywordwrapFilter to significantly improve the comfort and user experience of reading long content on the article detail page.

Why long content needswordwrap?

The reading experience of long text on web pages is often limited by the actual width of the screen.When a line of text is too long, the reader's eyes need more time and effort to locate the beginning of the next line, which not only slows down the reading speed but also easily causes skipping lines or misreading, seriously affecting the continuity of reading.This visual discomfort is one of the main reasons for user loss.

wordwrapThe core function of the filter is to automatically wrap long text content and ensure that the number of characters per line remains within a reasonable range.This can effectively reduce the horizontal movement burden on the reader's eyes, making the text appear clearer and easier to follow in visual blocks.By controlling the number of characters per line, it can make the text visually more breathable, no longer dense as a whole, thereby greatly improving the comfort of reading.

It is worth noting that,wordwrapThe filter mainly intelligently breaks lines by identifying space characters in the text. This means that if the content of the article is English or mixed with Chinese and English,wordwrapCan be well inserted between words to avoid long lines. However, for pure Chinese text without any spaces,Chinese text, because there is no natural space between Chinese words,wordwrapThe filter willDo not automatically wrap Chinese words in the middle. If your article is mainly continuous Chinese text and needs to implement strict character length control for line breaks, it may need to combine front-end CSS ofword-break: break-all;Property, or manually segment the content during editing for a more refined **effect.

How to apply in AnQiCMSwordwrap?

Apply in AnQiCMSwordwrapThe filter is very intuitive. First, we need to find the template file that controls the display of the article detail page. According to the AnQiCMS template conventions (refer todesign-director.mdDocument), the article detail page template is usually located attemplate/你的模板目录/模型table/detail.htmlortemplate/你的模板目录/archive_detail.html(The specific file name may vary depending on the type of your model and template design).

Open this template file and locate the tag responsible for outputting the main content of the article. Usually, this will be something similar to{% archiveDetail articleContent with name="Content" %}such a structure, wherearticleContentIt is the variable used to receive the article content (you may have used a different variable name), andname="Content"then specifies the field of the article content to be retrieved.

Then, towordwrapApply the filter to this variable and specify an appropriate line character limit. Additionally, since the content of the article (especially that entered through a rich text editor) often contains HTML tags, we also need to combinesafeto use the filters together.

Example code as follows:

{# 假设 archiveContent 变量包含了从后端获取到的文章 HTML 内容 #}
<div>
    {%- archiveDetail articleContent with name="Content" %}
    {{ articleContent|wordwrap:80|safe }}
</div>

In the above example,80Indicate that we want to display a maximum of about 80 characters per line (including spaces). This number can be flexibly adjusted based on your website design, font size, and the reading habits of your target user group, in order to