In the daily content publishing work, we often need to insert various URLs into articles, some starting with HTTP and some with HTTPS. Manually add URLs to each one.<a href="...">Tags are not only inefficient, but also prone to errors, especially when dealing with large amounts of content. Anqi CMS is well aware of these pain points for content creators, and therefore integrates powerful and intelligent features into the template engine.urlizeFilter, designed to make the automation of URL link processing easy.

urlizeFilter: Smart recognition and protocol maintenance

Of Security CMSurlizeThe filter is specifically designed to solve this pain point. Its core function is to automatically identify and convert URLs and email addresses in plain text into clickable HTML links, greatly reducing the burden on content editors.

About the URL that contains both HTTP and HTTPS protocols,urlizeThe filter performs very intelligently and respects the original text. It will not arbitrarily convert all links to a single protocol, but will accurately identify and maintain the protocol declared in the URL:

  • When your text explicitly contains ahttp://URL that starts withurlizeThe protocol will be retained as is, generating ahttp://link of the protocol. For example, if you enter这是我的网站:http://www.example.comit will be converted to<a href="http://www.example.com" rel="nofollow">http://www.example.com</a>.

  • Similarly, if the URL starts withhttps://,urlizeit will also ensure that the generated link uses a securehttps://protocol. For example,请访问我的安全页面:https://secure.example.comIt will be converted into<a href="https://secure.example.com" rel="nofollow">https://secure.example.com</a>.

  • It is also worth mentioning that even if you only entered something likewww.example.comOrexample.comSuch URLs without a protocol prefix,urlizewill also automatically supplement them withhttp://a protocol, ensuring they become valid clickable links.

This fine-grained processing of different protocol URLs brings great convenience to content operations, you don't have to worry about protocols being incorrectly converted, leading to link failure or security prompts. At the same time, in order to comply with SEO practices, ...urlizeThe filter will also automatically add to these generated linksrel="nofollow"This means that when search engines crawl your website, they will not pass any weight through these links, which helps you better control the SEO effect of your website.

How to useurlizeFilter

Using in Anqi CMS template,urlizeThe filter is very intuitive. You just need to pass the text variable containing the URL through the pipe symbol|pass tourlizeAnd the filter can be. SinceurlizeThe filter generates HTML code, so it usually needs to be配合|safeFilters are used together to ensure that the browser can correctly parse these HTML and not display them as plain text.

For example, if your article content is stored in a file namedarchiveContentIn the variable, you can call it like this:

<div>
    {{ archiveContent|urlize|safe }}
</div>

This way,archiveContentAll URLs and email addresses in it will be automatically converted to those with the correct protocol andnofollowThe HTML link of the attribute greatly enhances the efficiency of content editing and the standardization of website content. If you want the generated link to be displayed more succinctly, for example, only showing part of the URL,urlizetruncThe filter provides additional truncation functionality, which will use an ellipsis after the specified length...to replace the excess part, but its handling logic for HTTP and HTTPS protocols is the same asurlizeIt is completely consistent.

Summary

Of Security CMSurlizeThe filter identifies and automatically links conversion functions through its intelligent protocol, greatly simplifying the work of content editors. It can accurately handle HTTP and HTTPS links and automatically add SEO-friendlyrel="nofollow"Ensure that your website content achieves a good balance between aesthetics, user experience, and search engine optimization.This feature is another embodiment of Anqi CMS's commitment to providing an efficient and user-friendly content management solution, allowing you to focus more on creating high-quality content.


Frequently Asked Questions (FAQ)

  1. urlizeDoes the filter process email addresses in text?Yes,urlizeThe filter not only recognizes and converts URLs, it also recognizes email addresses in text and converts them into clickablemailto:links, such as[email protected]It will be converted into<a href="mailto:[email protected]" rel="nofollow">[email protected]</a>.

  2. Does the generated link support custom attributes, such as removingrel="nofollow"?According to the AnqiCMS documentation,urlizeThe filter defaults to automatically adding attributes to the generated linkrel="nofollow"Attribute, this is to follow the SEO**practice. The document does not directly mention the method to cancel or customize this attribute through parameters.If you need more flexible link attribute control, you may need to manually write HTML links, or consider using custom template tags or JavaScript for more advanced processing.

  3. urlizeandurlizetruncWhat are the differences between filters? urlizeThe filter will convert URLs in the text to full clickable links, displaying the original URL. AndurlizetruncThe filter adds a truncation feature on this basis, allowing you to specify the maximum display length of the link text. The part exceeding the specified length will be...Replace, making it more concise. Both handle the logic of HTTP/HTTPS protocols in the same way.