When managing website content, we often need to convert URLs or email addresses in text to clickable links.Manually adding HTML tags one by one is time-consuming and prone to errors, especially when dealing with large amounts 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 for small and medium-sized enterprises and content operation teams, understands the importance of such needs. It integrates many practical tools in the template engine to simplify this work, among whichurlizeThe filter is a major highlight. This filter can automatically identify URL patterns in text and wrap them in HTML's<a>In the tag, it greatly reduces the workload of content editing, and by default, it will also add attributes to these automatically generated links.rel="nofollow"This is usually beneficial for the website's SEO strategy.
Then, for email addresses, such as common[email protected],urlizeWhether the filter can also intelligently recognize and convert intomailto:Where is the link? The answer is yes. According to the relevant documentation of the AnQiCMS template filter,urlizeThe filter indeed supports the intelligent parsing of 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[email protected]Get more information afterurlizeThe filter is processed, and it is displayed on the front-end page[email protected]It will automatically become a link that can be clicked directly to call the user's local email client to send an email.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 that the content of your article is stored inarticle.ContentIn the variable, you can use it like thisurlizeFilter:
{{ article.Content | urlize | safe }}
Here|safeIt is a very critical filter that tells the AnQiCMS template engine, after passing throughurlizeThe processed content is safe HTML code that should be rendered directly, not escaped as plain text. If there is no|safe, the browser may treat<a href="mailto:...">...</a>This HTML code is displayed itself, not a clickable link.
In addition to email addresses,urlizeThe filter also supports identifying various standard URL formats, including those that start withhttp:///https://complete URLs starting withwww.yourwebsite.comeven bare domain namesyourwebsite.comFor scenarios that require controlling the display length of links, AnQiCMS also providesurlizetruncA filter that can truncate link text to a specified length while converting links and replace the excess part with an ellipsis (...) to make the page layout neater.
In summary, AnQiCMS'surlizeThe filter is a very practical content operation tool, it can not only efficiently convert URLs in ordinary text into clickable links, but also intelligently handle email addresses and automatically generatemailto:Linking this, it greatly optimizes the process of content editing and publishing while enhancing the readability of content and user interaction.
Frequently Asked Questions (FAQ)
1. Why when usingurlizeWhen adding a 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</>/&. WhenurlizeThe filter has generated<a>When labeling such HTML code, if not using|safeThese tags themselves will be escaped, causing the HTML source code to be displayed on the page instead of clickable links. Add|safeIt is explicitly told to the template engine that this content is checked, safe HTML code that can be safely rendered.
2.urlizeDoes the filter support converting phone numbers to clickabletel:links?According to the current document description ofurlizeand the example of the filter,urlizePrimarily focused on parsing standard URL formats(http/https/wwwand naked domain names) and email addresses. The document does not explicitly mention the automatic recognition and conversion of123-456-7890)tel:Link support. If this feature is needed, it may require combining with custom JavaScript or other template logic.
3. If I don't want to leturlizeLinks generated automatically containrel="nofollow"Can the properties be modified?The AnQiCMS documentation points outurlizeThe filter will automatically add properties to the links parsed outrel="nofollow"Currently, the properties are,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 link generation, or consider using custom template logic to build links instead of relying entirely onurlizefilter.