How to automatically parse URL strings to make them clickable in the article body or description,` tag?

Calendar 👁️ 64

In daily website content creation and management, we often need to embed some links in the article text or description, such as referencing external resources, pointing to product pages, or other related articles.If these URLs are only displayed in plain text, users will have to manually copy and paste them into the browser, which will undoubtedly greatly reduce their user experience.Fortunately, AnQiCMS is built-in with very practical features that can automatically identify and convert these URL strings into clickable ones<a>tags, making the website content more friendly and convenient.

This feature is mainly implemented through the template filter of AnQiCMS, which can intelligently scan text content, find strings that match the URL format, and then automatically add HTML hyperlink tags to them.This not only improves the user's browsing efficiency, but also ensures consistency of content, saving us the麻烦 of manually editing each link.It is especially worth mentioning that the automatically generated links will also be added by defaultrel="nofollow"Attribute, this is a very considerate detail for the website's SEO strategy, which helps to better manage the weight transmission of external links.

urlizeUse of filters

AnQiCMS providedurlizeThe filter automatically completes this conversion. Its usage is very simple, just add it to the text variable that needs to be processed|urlizeIt can be. For example, if your article content is stored inarchive.ContentThis variable, then you can write it like this in the template:

{{ archive.Content|urlize|safe }}

Pay special attention here when usingurlizeAfter the filter, we still need to add one|safefilter was used. This is becauseurlizeThe filter generates HTML code (i.e.<a>Tags), while the AnQiCMS template engine, for security reasons, defaults to escaping all output HTML characters and converting them to HTML entities (for example<Will become&lt;If it is not added|safeFilter, then the generated link will be displayed as text&lt;a href="..."&gt;...&lt;/a&gt;, rather than a clickable link.|safeThe function is to inform the template engine that this content is safe HTML code that can be output directly without escaping.

For example, suppose you have a section of content in your article:

欢迎访问我们的官方网站:https://en.anqicms.com,同时您也可以发送邮件到 [email protected] 获取帮助。

after{{ archive.Content|urlize|safe }}After processing, it will be displayed on the front-end page as:

欢迎访问我们的官方网站:<a href="https://en.anqicms.com" rel="nofollow">https://en.anqicms.com</a>,同时您也可以发送邮件到 <a href="mailto:[email protected]" rel="nofollow">[email protected]</a> 获取帮助。

As you can see,urlizeIt also recognizes standardhttp(s)://Link, even email addresses are recognized and converted.mailto:Link, very smart.

More flexible control:urlizetrunc

Sometimes, the URLs in our articles may be very long, and displaying them directly can affect the layout aesthetics. AnQiCMS provides this forurlizetruncFilter, it isurlizeThe function of truncating the link display text has been added.

urlizetruncThe filter requires a numeric parameter to specify the maximum length of text displayed for the link. If the length of the original URL string exceeds this value, it will be truncated and an ellipsis will be added at the end....

How to use as an example:

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

Following the above example, if you use:{{ archive.Content|urlizetrunc:20|safe }}To be processed:

Original content:欢迎访问我们的官方网站:https://en.anqicms.com,同时您也可以发送邮件到 [email protected] 获取帮助。

After processing (text limit is 20 characters):

欢迎访问我们的官方网站:<a href="https://en.anqicms.com" rel="nofollow">https://www.anqicms...</a>,同时您也可以发送邮件到 <a href="mailto:[email protected]" rel="nofollow">[email protected]...</a> 获取帮助。

In this way, even long URLs can be presented in a more concise and beautiful way on the page, maintaining the cleanliness of the content.

Examples of actual application scenarios

This feature is very useful in various text content areas of AnQiCMS, for example:

  • The article body (archive.Content)This is the most common application scenario, ensuring that users can easily click on the reference links contained in long articles.
  • Category description (category.Description)When mentioning external resources or related topics in the category page description, links can be automatically generated.
  • Single-page content (page.Content)For example, pages such as “About Us” or “Contact Information”, if they contain websites or email addresses, can also be automatically linked in this way.

By simply adding to the template|urlize|safeor|urlizetrunc:数字|safeYou can let AnQiCMS automatically handle URLs in the text, greatly enhancing the interactivity and accessibility of the website.This reflects AnQiCMS's thoughtful consideration in improving content operation efficiency and user experience.

Frequently Asked Questions (FAQ)

1. Why did we useurlizeAfter the filter, the link is still displayed as text instead of clickable?This is usually because you forgot to add|safefilter.urlizeThe filter generates HTML code (i.e.<a>Tags), but the AnQiCMS template engine, for security reasons, defaults to escaping all output HTML characters. If not added|safe,<a>The angle brackets and other special characters in the tag will be converted to HTML entities, causing the browser to fail to correctly parse them as clickable links.

2.urlizeThe links generated by the filter will be automatically added.rel="nofollow"Are you? Can I remove it?Yes, according to the design of AnQiCMS,urlizeThe filter will default to generating when automatically parsing URLs<a>tagsrel="nofollow"Property, this helps manage the SEO impact of external links. Currently throughurlizeThe filter itself does not have any parameters that can remove or modify thisnofollowProperty. If you have specific requirements to remove this property, you may need to consider other processing methods, such as manually inserting HTML links in the background content editor, or engaging in secondary development to customize template functions.

3.urlizeWhat types of URL can the filter recognize? Does it support Chinese domain names? urlizeThe filter can recognize various common URL formats, including those starting withhttp:///https://Complete URLs starting withwww.The URL at the beginning (it will automatically prepend it)http://). In addition, it can recognize email addresses and convert them tomailto:Link. For Chinese domain names, as long as they are complete internationalized domain names (IDN) in the content (for example, after Punycode conversion)xn--...Form, or the Chinese form usually displayed by the browser), and conforms to the general pattern recognized by URLs.urlizeFilters can also usually correctly identify and convert.

Related articles

How can you clearly display the user's comment content, username, reply object, and posting time in the comment list?

In website content operation, the comment section is undoubtedly an important manifestation of user interaction and content depth.A well-designed, clear information presentation comment list that can significantly improve the user's browsing experience and effectively stimulate community activity.AnQiCMS's powerful template system provides us with flexible tools, allowing us to easily achieve the organization of comment content, commenters, reply objects, and posting time.### Understanding the Core Elements of Comment Lists To build a visually appealing and practical comment list, we need to ensure that several key pieces of information are presented intuitively

2025-11-08

How to use the `archiveFilters` tag to build a dynamic document filtering feature, such as filtering by product parameters?

Using AnQiCMS's `archiveFilters` tag to build an efficient and practical dynamic filtering function In the field of content management and e-commerce, users being able to quickly and accurately find the information they need is crucial for improving website experience and conversion rates.Imagine, when users browse products or documents on your website, if they can quickly filter out the content they want based on various conditions such as color, size, brand, and even more specific parameters like processor type, memory size, etc., this will greatly enhance their user experience.Provided by AnQiCMS

2025-11-08

How to customize and display a friendly shutdown notice when the website is in a closed state?

In website operation, we sometimes need to temporarily close the website, whether it is for system upgrades, data maintenance, or short-term business adjustments.It is crucial to display a friendly shutdown prompt to visitors in this case.This not only informs users of the website status, avoids unnecessary confusion, but also maintains the brand image and provides clear guidance for search engines.AnQiCMS (AnQiCMS) provides us with a flexible way to customize and display this information.### Enable website shutdown status and set basic prompts First, you need to set the website to shutdown status

2025-11-08

How to perform arithmetic operations such as addition, subtraction, multiplication, and division in the template and display the result?

In AnQiCMS template design, sometimes we need to perform arithmetic operations such as addition, subtraction, multiplication, and division on the numbers displayed on the page to present data more flexibly.Whether it is to calculate the total price of goods, display dynamic percentages, or perform simple processing of certain statistical data, AnQiCMS's template engine provides intuitive and powerful arithmetic calculation capabilities.AnQiCMS's template engine borrows the syntax style similar to Django templates, allowing us to directly output variables in template files (using `{{

2025-11-08

How to retrieve and display user group details, such as group name, level, and purchase price, for a membership system?

Today in the operation of the website, building an efficient member system is crucial for content monetization, user stickiness cultivation, and community construction.AnQiCMS (AnQiCMS) provides a solid foundation for building such a system with its flexible design and rich features.Among them, the fine management of user groups is the core of the member system's operation, which allows us to provide differentiated service experiences based on the different identities and rights of users.### User Group Management in AnQi CMS: Basics and Value AnQi CMS built-in user group management function

2025-11-08

How to reuse common HTML fragments in a template by using the `include` tag or define reusable code blocks by `macro`?

In the development and maintenance of website templates, we often encounter the need to reuse HTML code snippets or logical structures.If you always copy and paste, it is not only inefficient, but also once you need to modify it, you have to repeat the operation in multiple places, which is very prone to errors.AnQi CMS knows this point, it provides a template engine that adopts Django's syntax, through `include` tags and `macro` macro functions, allowing us to easily achieve code reuse, greatly enhancing the maintainability and development efficiency of templates.### Reuse the public HTML fragment: `include`

2025-11-08

How to set up image resource management in AnQi CMS and support batch regeneration of thumbnails in different sizes?

In website operation, images are not only an important part of the content, but also a key factor affecting page loading speed and user experience.Efficient image management can greatly enhance the performance and maintainability of a website.AnQiCMS (AnQiCMS) is well-versed in this field, providing users with comprehensive image resource management functions, especially excelling in thumbnail settings and batch processing, making image operations more convenient and flexible.### Core Feature Overview: AnqiCMS Image Management System AnqiCMS Image Resource Center is a collection of upload, classification, editing

2025-11-08

How to use `{filename}` or `{catname}` in pseudo-static rules to generate SEO-friendly custom URLs for articles, categories, and single pages?

In website operation, generating SEO-friendly URL addresses for content is a key link to improving website SEO performance.A clear, keyword-rich URL not only makes the page content easy for users to understand, but also helps search engines better understand and crawl web pages.AnQiCMS provides powerful custom static rule functionality, allowing us to flexibly use variables such as `{filename}` and `{catname}` to generate highly customized URLs for articles, categories, and even single pages.### Optimize URL

2025-11-08