How to make AnQiCMS automatically identify URLs and email addresses in text and convert them into clickable hyperlinks?

Calendar 👁️ 72

In daily website operation, we often need to mention URLs or email addresses in the article content.If this information is just plain text, users cannot directly click to jump, and they need to manually copy and paste, which undoubtedly increases the complexity of the operation, and may also cause users to lose interest. 幸运的是,AnQiCMS provides a very simple and efficient method that allows the website to automatically identify URLs and email addresses in text and convert them into clickable hyperlinks, greatly enhancing the user experience and interactivity of the website.

Why is automatic recognition and conversion so important?

Imagine when the user browses your product introduction or service details, if there is a technical support email or product purchase link on the page, and these links are live and clickable, the user can reach the required information immediately.This not only saves users' time, but also makes the website content appear more professional and modern.From the perspective of search engine optimization, appropriate internal and external links (even those withnofollowThe link of the attribute) also helps search engines better understand the structure and external reference relationships of the website content, althoughurlizeThe filter will be added automaticallyrel="nofollow"Properties, but it still helps to improve user experience, thus indirectly having a positive impact on SEO.

Magic of intelligent link conversion in AnQiCMS:urlizeFilter

In AnQiCMS, the key to achieving this automatic conversion lies in using a namedurlizeThe template filter. This filter can intelligently detect URLs in text content (including thosehttp:///https://starting withwww.starting with, or even bare domain names likeexample.com) and email addresses (such as[email protected]),then they are automatically added with<a href="...">tags to make them clickable hyperlinks. In order to follow the practices of Search Engine Optimization (SEO),urlizeThe filter will also automatically add to these generated linksrel="nofollow"Property.

To useurlizeThe filter, you just need to add it to the template variable behind the text content you need to process.

For example, on your article detail page, there is usually such code to display the article content:

{{ archive.Content|safe }}

Herearchive.Contentrepresents the main content of the article.|safeThe filter is used to inform AnQiCMS that this part of the content is safe HTML, which does not require additional HTML entity escaping, so that the rich text editor can display the layout effect normally.

Now, to automatically convert URLs and email addresses in it to clickable links, we just need to add|safebefore the filter,|urlize:

{{ archive.Content|urlize|safe }}

It's that simple! After refreshing the page, you will find that all the URLs and email addresses in the article content have turned into blue, clickable hyperlinks.

Control the length of the link text:urlizetruncFilter

Sometimes, your article content may contain very long URLs, and if displayed as is, it may affect the aesthetics and layout of the page. AnQiCMS has also considered this point and providedurlizetruncFilter. This filter is different fromurlizeFunction similar, it can also automatically recognize and convert URLs and email addresses, but it additionally allows you to specify the maximum display length of the hyperlink text. If the original URL text exceeds this length, the part that exceeds will be...An ellipsis is used to replace, thus keeping the page tidy.

urlizetruncThe usage is also very intuitive, you need to pass a numeric parameter to it, indicating the maximum number of characters you want the link text to display.

For example, if you want the link text to display a maximum of 30 characters:

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

This way, even if the original link is very long, only the first 30 characters will be displayed on the page, followed by an ellipsis.When the user clicks on this truncated link, it will still jump to the full original URL.

Where can these filters be used?

These filters are mainly suitable for fields that contain a large amount of text, such as:

  • Article detail page(archive.ContentThe most common application scenario makes it easier to use the reference links and contact information in your blog posts and news updates.
  • Single page content(page.ContentFor example, the official website link on the "About Us" page, or the email address on the "Contact Us" page.
  • Other rich text or long text custom fieldsIf your content model defines other long text fields and you expect them to contain URLs or email addresses, you can also apply these filters.

Please note when using, due tourlizeandurlizetruncGenerate HTML tags, therefore, they are usually followed by|safefilters to ensure that the browser can correctly parse and render the HTML code.

By making such a simple configuration, you can make the AnQiCMS website's content more intelligent and interactive, providing visitors with a smoother browsing experience while maintaining the professionalism of the website's content.

Frequently Asked Questions (FAQ)

1. How do I prevent certain paragraphs of text on my website from being automatically translated?

If you do not want a specific text paragraph's URL or email address to be automatically converted to a link, the most direct method is to avoid using the corresponding template variable in the paragraph.|urlizeor|urlizetruncFilter. You can choose to output this part of the content in a separate variable that does not need to be automatically converted.If the content is entered using a rich text editor, you can also manually remove the link from the editor, or ensure that it is not a standard URL or email format to prevent it from being identified by the filter.

How to choose to useurlizeOrurlizetrunc?

It mainly depends on your needs for the beauty of the page

  • If there are not many URLs in your content, or most URLs are of moderate length,urlizeIt is enough, it will display the full URL text, more complete information.
  • If your content often contains long URLs, useurlizetruncIt can make the page layout neater, avoiding long links from breaking the visual balance. You can adjust according to the actual effect.urlizetrunc:数字To find the display length that is most suitable for your website.

3. How does this feature affect SEO?

urlizeandurlizetruncThe filter will automatically add to the generated linkrel="nofollow"The attribute informs the search engine that this link should not be used to pass "weight" or as a recommendation.This means that these automatically generated links will not directly boost the search engine ranking of the target page.However, this feature has a significant positive impact on user experience (UX), making it easier for users to click and access relevant information.A good user experience is an indirect factor affecting SEO, because users are more willing to stay longer on a website with a good experience, which helps to reduce the bounce rate and increase the depth of page visits, all of which are important indicators for search engines to measure the quality of a website.Therefore, although it isnofollowLinks, they still have a positive impact on the overall SEO performance of the website.

Related articles

How to replace the old keyword with a new keyword in the AnQiCMS template?

When operating website content on AnQiCMS, we often encounter situations where we need to make minor adjustments to the website text content.Sometimes it's a change in brand words, sometimes it's the correction of typos, or adjusting the copy temporarily to cater to specific marketing activities.When these modifications need to be reflected at specific locations on the website front-end template rather than the global database, AnQiCMS provides a flexible and efficient solution.### Understand the need for keyword replacement within templates The AnQiCMS backend usually provides the "site-wide content replacement" function, which is powerful and convenient

2025-11-08

How to remove the specified characters or extra spaces from the AnQiCMS string?

In website content operations, we often encounter situations where we need to process strings, such as cleaning up user input data, standardizing display content, or removing unnecessary characters and extra spaces from text.These seemingly minor operations can significantly improve the neatness and professionalism of website content.As an AnQiCMS user, you will find that the system provides powerful and flexible template filter functions that can easily meet these string processing needs.

2025-11-08

How to convert all English characters to uppercase or lowercase in the AnQiCMS template?

In the display and management of website content, maintaining uniformity in text formatting is a key factor in improving user experience and maintaining brand image.Especially the capitalization of English characters, sometimes it is necessary to unify it according to design or business needs.AnQiCMS as an efficient and flexible content management system fully considers these needs, and provides us with a quick and easy method for English character case conversion through its powerful template function.

2025-11-08

How to safely extract from an article summary containing HTML tags without damaging the HTML structure?

In website operation, the abstract of the article plays a vital role.It is not only the first window to attract visitors to click, but also an important basis for search engines to understand page content, index, and rank.A good abstract can quickly convey the core information of the article, enhance user experience, and help with SEO performance.However, when the content of the article itself contains rich HTML tags (such as images, links, bold, paragraphs, etc.), how to safely extract a summary from these contents while avoiding destroying the HTML structure has become a common challenge.

2025-11-08

How to automatically truncate a long URL and display an ellipsis in the middle when displaying it in AnQiCMS?

In website content operation, we often encounter the problem that long URLs cause poor page layout and affect user experience.Especially on list pages, navigation, or other display areas, if the original URL is displayed without processing, it may take up too much space and even burst the layout.In AnQiCMS, fortunately, we can elegantly solve this problem through flexible template filters, to achieve automatic truncation of long URLs and display ellipsis at the end or at a specific position.

2025-11-08

How to automatically convert line breaks in the multi-line text entered by the user to the HTML `<br>` tag?

When using Anqi CMS to publish content, we often encounter such situations: when entering text in the content editing box, if it contains multiline information, but when the front-end page displays it, these line breaks disappear, causing the text to be squeezed together and resulting in a poor reading experience.This is usually because HTML defaults to treating newline characters (`\n`) as regular spaces.However, Anqicms provides a very convenient template filter that can help us easily solve this problem, allowing multi-line text to maintain its original formatting on the web page.### Core Function

2025-11-08

How to implement string capitalization or capitalize each word in AnQiCMS templates?

In website content operation, the way text is displayed often directly affects the reading experience and the professionalism of the website.AnQi CMS as an efficient content management system, its powerful template engine provides us with flexible content display capabilities.This includes various string formatting processes, such as what we will discuss today, how to capitalize the first letter of a string, or the first letter of each word.

2025-11-08

How to flexibly display content based on different content models?

AnQiCMS is a system designed for efficient content management, one of its core advantages lies in its flexible content model, which allows the display of website content to be highly customized according to business needs and user experience.To make full use of the AnQiCMS content model to achieve flexible display, we can understand and operate from the following aspects.First, **understanding the essence and role of the content model** is fundamental.In AnQiCMS, the content model is not just a term for predefined categories like 'article' or 'product'

2025-11-08