In the AnQiCMS template system, the way content is processed is flexible and clear. When you encounter a long text area that seems to be automatically wrapped, and you want to control it, you first need to understand the filters in AnQiCMS (filterThe mechanism. This is not the default behavior of AnQiCMS, but it is implemented by explicitly calling a specific filter in the template.

UnderstandingwordwrapThe principle of the filter.

wordwrapIs provided by AnQiCMS as a template filter, its main function is to automatically wrap strings according to the specified character length. When a long text content has too many consecutive characters without spaces, wordwrapThe filter will force a line break after a specified length to prevent content overflow or layout inconvenience.

For example, if you use it in a template like thiswordwrapFilter:

{{ "这是一个非常长的连续文本,它需要被自动换行展示以便于阅读。"|wordwrap:10 }}

The output might look like this:

这是一个非常
长的连续文本,
它需要被自动
换行展示以便
于阅读。

This example shows,wordwrapThe filter only takes effect when you explicitly call it in the template code and specify a numeric parameter to define the line break length. This means that AnQiCMS will not automatically apply it to all your long text content by default.wordwrapProcess.

A control method for a specific long text area

When you want to “disable”wordwrapWhen filtering, the actual task is to ensure that there is no explicit call to the template code displaying the long text content|wordwrapThis filter. The content fields in AnQiCMS, such as document content, single-page content, or category descriptions, are usually output in the template in the following way:

{# 文档详情页的内容输出 #}
<div>
    {{ archive.Content|safe }}
</div>

{# 单页详情页的内容输出 #}
<div>
    {{ page.Content|safe }}
</div>

{# 分类详情页的内容输出 #}
<div>
    {{ category.Description|safe }}
</div>

Here|safeThe filter is crucial, its role is to inform the template engine that this content is safe HTML code, which does not require further escaping and should be parsed and displayed directly. If your long text content already contains HTML tags (such as content input from a rich text editor), use|safeEnsure that these HTML tags are rendered correctly and not displayed as plain text.

Therefore, to control or "disable"wordwrapThe filter, you just need to:

  1. Check your template file:Find the specific template code segment that displays this long text content. These files are usually located in your theme directory.templatethe folder, for examplearchive/detail.html/page/detail.htmlorcategory/list.htmletc.
  2. Find and remove|wordwrap:Check if there is any after the variable where the text content is output.|wordwrap:数字Such a call. If it exists, please delete it. For example, the{{ archive.Content|wordwrap:80|safe }}is modified to{{ archive.Content|safe }}.

By making such adjustments, you can ensure that AnQiCMS will not apply automatic line breaks to specific long text areas.The display of content will depend entirely on its original format (such as HTML saved from a rich text editor, or HTML converted from Markdown) and the CSS styles applied by your website application.

Additional considerations involving Markdown content.

It is worth mentioning that if your long text area supports Markdown format editing (for example, if Markdown editor is enabled in the background content settings), and you want the Markdown content to be correctly rendered as HTML on the front end, you may also seerenderThe combination of parameters. For example:

{# Markdown内容渲染为HTML #}
<div>
    {%- archiveDetail articleContent with name="Content" render=true %}
    {{articleContent|safe}}
</div>

Hererender=trueEnsured that Markdown text is converted to HTML, while|safethen it ensures that the converted HTML can be displayed normally.wordwrapthe filter meetsrenderor|safeIt is an orthogonal relationship, they handle different aspects of text.wordwrapFocus on the visual line breaks of text,renderFocus on the conversion from Markdown to HTML,|safePay attention to the safe output of HTML.

Summary and suggestions

In AnQiCMS, forwordwrapThe control of the filter is very intuitive: it is a tool used as needed, not a mandatory default setting.If you do not want it to take effect, just make sure it is not added to your template code.Always recommend thorough testing after modifying the template to ensure content displays as expected.If the content still appears with unexpected line breaks, it is likely due to CSS style rules or the behavior of the browser itself. In this case, check the CSS file instead of the filter configuration.


Frequently Asked Questions (FAQ)

1. I didn't see in the template.|wordwrapBut the long text still appeared to wrap automatically, why is that?Answer: If the template does not explicitly call|wordwrapThe filter, but the content still wraps automatically, which is usually caused by CSS styles or browser default behavior. For example, if your text content is placed in a container with a fixed width and appliedword-break: break-all;oroverflow-wrap: break-word;In the container of CSS properties, the browser will force a line break to adapt to the container width. It is recommended to check the related CSS files to see if there are any style rules for the text area.

2.|wordwrapFilters and|linebreaks/|linebreaksbrWhat are the differences between filters?Answer: They are all related to text line breaks, but their mechanisms are different.|wordwrapThis is to force a line break at the specified character count, even in the middle of a word (if the specified parameter is small enough). And|linebreaksand|linebreaksbr(as well as|linenumbersIt is mainly to keep the existing line breaks in the text (`)转换为HTML的
标签或

标签。换句话说,wordwrap是生成新的换行,而The linebreaks series is for parsing and rendering existing line breaks.

3.wordwrapCan the filter be globally disabled instead of checking everywhere?Answer: The filter design of AnQiCMS is applied to a single variable, it is not a global setting. Therefore, it cannot be disabled through a global switch.wordwrapFilter. If multiple places in your website template use|wordwrapAnd you want to remove it uniformly, you need to check and modify the corresponding calls in the template file.This design provides extremely high flexibility, but it also means that a certain understanding of the template code is required for precise control.