When managing website content, we often need to convert URLs or email addresses in the text to clickable links.It takes time and is prone to errors to manually add HTML tags one by one, especially when dealing with a large amount of content.Therefore, whether a content management system can provide intelligent link parsing functionality is crucial for content operation efficiency.

AnQiCMS as a content management system designed specifically for small and medium-sized enterprises and content operation teams, understands the importance of such needs. It has built-in many practical tools in the template engine to simplify this task,urlizeThe filter is a major highlight. This filter can automatically identify URL patterns in text and wrap them in HTML's<a>Tags, greatly reducing the workload of content editing, while the default will also add English for these automatically generated links.rel="nofollow"Properties, which is usually beneficial for the SEO strategy of the website.

Then, for email addresses, such as common[email protected],urlizeCan the filter also intelligently recognize and convert intomailto:What's the link? The answer is yes. According to the relevant documents of AnQiCMS template filters,urlizeThe filter indeed supports intelligently parsing email address strings and automatically generating themmailto:The link of the protocol.

This means that when you enter text containing an email address in the article content, description, or other text fields, for example, “If you have any questions, please contact us:[email protected]Get more information",经过urlizeAfter filter processing, on the frontend page",过滤器处理后,前端页面上[email protected]It will automatically become a link that you can click to send an email directly using the local email client.This convenience greatly enhances the user experience and reduces the repetitive labor of content creators and operators.

It is very intuitive to apply this filter in the AnQiCMS template. Assuming your article content is stored inarticle.ContentIn the variable, you can use it like thisurlizeFilter:

{{ article.Content | urlize | safe }}

Here are the|safeIt is a very critical filter that tells the AnQiCMS template engine,urlizeThe processed content is safe HTML code and should be rendered directly, not escaped as plain text. If not|safe, the browser may interpret as<a href="mailto:...">...</a>This HTML code displays itself, not as a clickable link.

In addition to the email address,urlizeThe filter also supports recognizing various standard URL formats, including those that start withhttp:///https://the complete URL at the beginning, as well as those that omit the protocolwww.yourwebsite.com, even bare domain namesyourwebsite.com. For scenarios that require controlling the display length of links, AnQiCMS also providesurlizetruncFilter, which can truncate the link text to the specified length while converting the link, and replace the exceeded part with an ellipsis (...) to make the page layout more tidy.

In summary, AnQiCMS'surlizeA filter is a very practical content operation tool, it not only can efficiently convert URLs in ordinary text to clickable links, but also can intelligently handle email addresses, and automatically generatemailto:Links, thereby greatly optimizing the content editing and publishing process while enhancing content readability and user interaction.


Common Questions (FAQ)

1. Why you need to addurlizethe filter, you also need to add|safeFilter?AnQiCMS's template engine defaults to HTML-escaping all output content to prevent potential XSS (Cross-Site Scripting) risks. This means that like</>/&Such special characters will be converted to&lt;/&gt;/&amp;). WhenurlizeThe filter has generated<a>When tags such as this HTML code are used, if not using|safeThese tags themselves will also be escaped, resulting in the display of HTML source code on the page instead of clickable links. Add|safeIt explicitly tells the template engine that this content is checked and safe HTML code that can be rendered directly without any worries.

2.urlizeFilter whether the phone number can be converted to clickabletel:link?According to the current document description of AnQiCMS andurlizefilter examples,urlizeMainly focuses on parsing standard URL formats (http/https/wwwand naked domain names). The document does not explicitly mention the recognition and conversion of phone numbers (such as123-456-7890) to automatic.tel:The support for links. If this feature is needed, it may require combining with custom JavaScript or other template logic.

3. If I don't want tourlizeEnglish generated link withrel="nofollow"Property, can it be modified?AnQiCMS document points outurlizeThe filter will automatically add properties to the parsed linksrel="nofollow"Currently, urlizeThe filter itself does not provide direct parameters to disable or modify thisnofollowbehavior. If the website has special requirements, such as needing to set internal links or specific external links todofollowMay need to perform DOM operations through JavaScript after the link is generated, or consider using custom template logic to build the link instead of relying on it completelyurlizeFilter.