The implementation of this feature is mainly due to the powerful filter provided by the Anqi CMS template engine.urlizeandurlizetrunc。They act as intelligent text assistants, automatically scanning your content to find potential links and email addresses and convert them into standard HTML<a>Label.

Smart Link Conversion:urlizeFilter

urlizeThe filter is a core tool in Auto CMS used for automating link conversion. When you paste a segment containing a URL (for examplehttp://www.anqicms.com/https://anqicms.comevenwww.anqicms.com), or an email address (such as[email protected]The text applies this filter automatically, it will wrap these text fragments in clickable hyperlinks.

The main advantage of this feature is:

  • Enhance user experience:Visitors can directly click to access related pages or send emails without manually copying and pasting, making content interaction more smooth and natural.
  • Simplify content creation:The operator can directly input the original URL or email address when writing content, without manually adding it<a href="...">Tags save a lot of time and reduce the possibility of errors.
  • SEO-friendly:By default,urlize转换生成的链接会自动带有Englishrel="nofollow"Property.This is very helpful for controlling the weight transfer of external links on the website and avoiding unnecessary SEO risks.If your website needs to pass weight to these external links, it can also be adjusted through additional SEO strategies.

In the templates of Anqi CMS, useurlize过滤器非常简单。您只需将需要处理的文本变量通过管道符号English|Pass tourlize过滤器即可。由于EnglishurlizeIt will generate HTML tags. To ensure that these HTML codes are rendered correctly rather than being escaped as plain text by the browser, it is also necessary to use them in conjunction.safeFilter.

Example:

Assuming you have a namedarticle.ContentThe variable, which contains the article's main content:

<p>欢迎访问安企CMS官网:http://www.anqicms.com,如果您有任何问题,可以发送邮件至 [email protected]。</p>

In the template, you can use it like this:urlizeFilter:

{{ article.Content|urlize|safe }}

After rendering, this content will automatically become:

<p>欢迎访问安企CMS官网:<a href="http://www.anqicms.com" rel="nofollow">http://www.anqicms.com</a>,如果您有任何问题,可以发送邮件至 <a href="mailto:[email protected]" rel="nofollow">[email protected]</a>。</p>

You can also useurlizea filter to control whether the link content is HTML-escaped, for exampleurlize:trueorurlize:falseThe specific requirements depend on your needs, but usually it is related tosafeused together,urlizeThe default behavior of can meet most scenarios.

Optimize display:urlizetruncFilter

Sometimes, the URL in the content may be very long, and displaying it completely may affect the beauty and reading experience of the page.urlizetruncThe filter is designed to solve this problem. It isurlizeBased on that, it has added control over the display length of linked text.

urlizetruncThe working method of the filter is withurlizeSimilar, but it allows you to specify a numeric parameter to limit the maximum number of display characters for the link text. If the text length of the original URL exceeds this limit,urlizetruncEnglish will be added at the end of the link text....This indicates that the content has been truncated, but the actual link is still the original full URL.

Example:

This continues from the previous context.article.ContentVariables, and hope to limit the display length of the link text to 20 characters within:

{{ article.Content|urlizetrunc:20|safe }}

After rendering, this content may be displayed as:

<p>欢迎访问安企CMS官网:<a href="http://www.anqicms.com" rel="nofollow">http://www.anqicms.com...</a>,如果您有任何问题,可以发送邮件至 <a href="mailto:[email protected]" rel="nofollow">[email protected]...</a>。</p>

(The specific truncation position and ellipsis may vary depending on the actual text and character set. This is just an example.)

PassurlizetruncYou can maintain the page's cleanliness and consistency, especially in lists, summaries, or any area that requires controlling text length, where it plays an important role.

**Practice and Application Scenarios

In the Anqi CMS,urlizeandurlizetruncThe filter is most commonly used in article detail pages, product descriptions, comment board content, comment sections, and other user-generated content or dynamic text areas.They ensure that all URLs and email addresses in the input text are presented in a user-friendly manner without manual intervention.

When using, please remember|safethe importance of filters. Becauseurlizeandurlizetruncit will generate HTML code, if missing|safeThese HTML codes will be displayed as plain text, rather than being parsed by the browser as clickable links.

English CMS through these intelligent filters not only simplifies the workflow of content operators, but also provides a more convenient and efficient browsing experience for website visitors.No matter whether your content is a long essay or a brief introduction, these tools can bring the links and contact information within it to life.


Common Questions and Answers (FAQ)

Q1: Why does the page display plain text instead of clickable links when I enter a URL or email address in the content?A1: This is very likely because you appliedurlizeorurlizetruncthe filter without immediately using|safeFilter. The Safe CMS defaults to escaping the output HTML code to prevent security issues. WhenurlizeFilter Generation<a>the tag is generated,|safeExplicitly tell the system that this part of the content is safe HTML that can be directly parsed and rendered by the browser. Make sure your template code is similar{{ content_variable|urlize|safe }}.

Q2:urlizeCan I customize their styles for the converted links?A2: Yes, it is possible.urlizeby the filter generator<a>Labels are standard HTML elements, you can completely control their styles through CSS. For example, you can define them in the CSS file of your website.a[rel="nofollow"]or more generalaLabels style, to beautify these automatically generated links. You can set color, underline, font size, etc., to keep it consistent with the overall design style of your website.

Q3:urlizeDo you automatically recognize all link and email address formats? For example, domain names with Chinese characters or special symbols?A3:urlizeFilter primarily based on standard URL and email address formats (such ashttp:///https:///www./@English for recognizing and converting. For Chinese domain names that conform to the IDN encoding specification, if they are in the text asxn--The ASCII compatible form at the beginning, or presented in other standard, recognizable URL formats, is usually correctly identified. However, for overly special or non-standard text formats, or some text that is not an effective URL or email address but resembles them, urlizeMay not be correctly identified or converted. It is recommended to standardize the link format of the content before use to obtain **conversion effect.