In AnQiCMS template system, the way to process content 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 of (. This is not the default behavior of AnQiCMS, but it is achieved by explicitly calling specific filters in the template.

UnderstandingwordwrapThe working principle of the filter

wordwrapIs an AnQiCMS template filter provided, which mainly serves to automatically wrap strings according to the specified character length. When a long text content has too many continuous characters not separated by spaces,wordwrapThe filter will force a line break after the specified length to prevent content overflow or layout inconvenience.

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

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

The output may look like this:

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

It can be seen from this example,wordwrapThe filter will only take effect when you explicitly call it in the template code, and a numeric parameter is required to define the line break length. This means that AnQiCMS will not automatically apply to all of your long text content by defaultwordwrapProcessing.

Control method for a specific long text area

When you want to 'disable'wordwrapFiltering, in fact, is to ensure that there is no explicit call to the template code displaying this long text content in English|wordwrapThis filter. The content field in AnQiCMS, such as document content, single-page content, or category description, is 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 are the|safeThe filter is critical, 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 as HTML. If your long text content already contains HTML tags (for example, content entered from a rich text editor), use|safeIt can ensure that these HTML tags are rendered correctly rather than displayed as plain text.

Therefore, to control or "disable"wordwrapFilters, you just need:

  1. Check your template file:Find the specific template code section that displays this long text content. These files are usually located in your theme directory.templatefolder, for example.archive/detail.html/page/detail.htmlorcategory/list.htmletc.
  2. Find and remove.|wordwrap:After the variable is output in the text content, check if it exists. If it does, please delete it. For example, to|wordwrap:数字such calls. If they exist, please remove them. For example, to{{ archive.Content|wordwrap:80|safe }}Change 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 the 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.

consider additional factors involving Markdown content

It is worth mentioning that if your long text area supports Markdown format editing (for example, if the 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>

Here are therender=trueEnsures that Markdown text is converted to HTML,|safeand that the converted HTML is displayed normally.wordwrapFilter is related torenderor|safeIt is an orthogonal relationship, handling different aspects of text.wordwrapFocuses on the visual line breaks of text.renderFocuses on the conversion from Markdown to HTML.|safeFocus on the safe output of HTML.

Summary and Suggestions

In AnQiCMS,wordwrapThe control of the filter is very intuitive: it is a tool used on demand, 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 the content displays as expected.If the content still appears to have unexpected line breaks, it is likely due to CSS style rules or the behavior of the browser itself. In this case, you should check the CSS file rather than the filter configuration.


Common Questions (FAQ)

1. I didn't see|wordwrap, but the long text still appeared with automatic line breaks, why is that?Answer: If the template does not explicitly call|wordwrapFilter, but the content still wraps automatically, which is usually caused by CSS styles or the browser's default behavior. For example, if your text content is placed in an element 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 that you check the related CSS files to see if there are any style rules for this text area.

2.|wordwrapfilters and|linebreaks/|linebreaksbrWhat are the differences between filters?答:They are all related to text line breaks, but the mechanisms are different.|wordwrapIt is forced to insert a line break at the specified number of characters, even if it breaks the middle of a word (if the specified parameter is sufficiently small). And|linebreaksand|linebreaksbr(and|linenumbers) mainly includes the existing line breaks in the text (\n),<br />or<p>Label. In other words,wordwrapis to generate a new line,linebreaksThe series is to parse and render existing lines.

3.wordwrapCan the filter be globally disabled instead of checking everywhere?答:AnQiCMS的过滤器设计是针对单个变量应用的,它不是一个全局设置。因此,无法通过一个全局开关来禁用wordwrapFilter. If there are multiple places where your website template uses|wordwrapAnd you wish to remove it uniformly, then you need to check and modify the corresponding calls in the template files one by one.This design provides high flexibility, but it also means that a certain understanding of the template code is required for precise control.