How to automatically parse the URL string in the text of AnQiCMS to make it clickable?

Calendar 👁️ 66

In daily content operations, we often need to embed various external or internal links in articles, product descriptions, and even in category descriptions and other text content.However, manually converting these plain text URL strings one by one into clickable HTML links is not only time-consuming and labor-intensive, but also prone to link errors due to negligence, which affects user experience and search engine optimization.

AnQiCMS is well aware of this pain point, therefore it provides a clever and efficient mechanism that can intelligently identify URL strings in text, automatically parse them into clickable links with correct HTML tags, greatly enhancing the efficiency and accuracy of content publishing.

The core of intelligent parsing:urlizeandurlizetruncFilter

AnQiCMS is a powerful and flexible template system that uses its built-in Filters feature to automatically parse URLs in text. Among them,urlizeandurlizetruncThese filters play a core role.

When you output a piece of text that may contain a URL in the template, just simply applyurlizeFilter, AnQiCMS can automatically identify text that containshttp:///https://orwww.URL strings that start with, as well as email addresses that match the format, and convert them to standard<a>Label. It is worth mentioning that in order to better comply with SEO standards, AnQiCMS will also add a default external link to these links when parsing themrel="nofollow"Attribute, effectively avoid unnecessary weight loss.

For example, suppose you have a piece of text.{{ archiveContent }}Contains访问我们的官网:https://en.anqicms.com,或者发送邮件至 [email protected].You can use it in the template like this:

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

The page will eventually display as:

<div>
    访问我们的官网:<a href="https://en.anqicms.com" rel="nofollow">https://en.anqicms.com</a>,或者发送邮件至 <a href="mailto:[email protected]">[email protected]</a>
</div>

Please note that we have additionally used|safeFilter. This is because the AnQiCMS template system, to prevent cross-site scripting (XSS) attacks, defaults to escaping all output content to HTML.urlizeThe filter generates a string with HTML tags, if not using|safethese tags themselves will also be escaped into entity characters, causing links to not display normally. Use|safeExplicitly tell the system that this content is safe and does not need to be escaped.

In some cases, you may want to maintain the clickable nature of a link while also controlling its display length on the page, to avoid overly long URLs affecting the overall layout. At this point,urlizetruncThe filter comes into play. It is similar tourlizethe function, but after parsing, it can truncate the link text to the specified character length and add an ellipsis at the end (...)。For example, if you want to display a link with no more than 15 characters:

<div>
    {{ archiveContent|urlizetrunc:15|safe }}
</div>

This way, long URLs will be intelligently truncated to keep the page tidy.

Global considerations for link management

AnQiCMS intelligent processing of links does not stop at text parsing.As a mature content management system, it also provides a variety of link management functions, collectively building an efficient, secure, and SEO-friendly content ecosystem.

For example, in the content settings, you can choose whether to automatically filter external links. If you choose not to filter, the system will automatically add external links to the content.rel="nofollow"Label, thisurlizeThe default behavior of the filter is consistent, further strengthening the internal control of SEO.

Moreover, AnQiCMS also has a powerful "site-wide content replacement" feature, allowing you to update keywords or links on the website in bulk with one click.This can quickly and accurately complete large-scale link maintenance work when adjusting website content strategy, changing URL structure, or renaming the brand name, greatly improving operational efficiency.

For optimizing internal links, the "anchor text management" feature of AnQiCMS also plays an important role.You can preset keywords and corresponding links, so the system can automatically identify keywords and add anchor text links when publishing content. This not only improves the browsing experience of users within the site but also has a positive impact on the crawling and ranking of search engines.

From a broader perspective, functions such as 'fake static rules' and '301 redirect management' ensure the standardization, friendliness, and maintainability of URLs at the overall architecture level of the website, laying a solid foundation for the website's SEO performance.

Summary

In summary, AnQiCMS passes throughurlizeandurlizetruncSuch an intelligent filter, supplemented by other perfect link management tools, greatly simplifies the processing process of URLs in the content.The operator only needs to focus on creating high-quality content, without worrying about manual link conversion, adding SEO properties, and maintaining global links.This automated and systematic management approach not only saves a lot of time and effort, but also ensures the professionalism of website content, the smoothness of user experience, and provides strong support for search engine optimization.


Frequently Asked Questions (FAQ)

1. Why when usingurlizeorurlizetruncPlus after the filter,|safe?AnQiCMS's template system, for website security, defaults to escaping all passed through{{变量}}grammatically output content to HTML.urlizeorurlizetruncThe filter will convert plain text URLs into HTML codes with tags.<a>If you do not add|safethese tags will be escaped as.<a>the tag itself will be escaped into&lt;a&gt;Entity characters that cause the page to only display text and cannot be clicked. Use|safeExplicitly tell the system that this part of the HTML content generated by the filter is safe and can be output directly without further escaping.

2.urlizeThe filter will automatically addrel="nofollow"Should I add the attribute?Yes,urlizeThe filter will automatically addrel="nofollow"Property. This design is to follow the suggestions of search engines, to help websites better control the transmission of link weight, and avoid unnecessary SEO risks.At the same time, AnQiCMS also provides the option 'Whether to automatically filter external links' in the 'Content Settings' section of the backend, further refining the strategy for handling external links.

3. Can I customizeurlizethe style of the parsed link (for example, adding a CSS class)? urlizeThe filter is mainly responsible for converting text to<a>Label, it does not add custom CSS classes by default. If you need to add styles to these automatically parsed links, you can do so through CSS selectors, for example, for<a>Labels or combine with the parent element for styling definition. If your needs are more complex and require dynamic addition of specific attributes when generating links, then you may need to consider manually adding links through a rich text editor at the time of content publication, or consider deeper template or system customization.

Related articles

How to display the category thumbnail and name in the article list?

## SecureCMS: Display category thumbnails and names elegantly in article lists In website operation, the article list page is an important entry point for users to browse content and discover information.A beautifully designed, informative list of articles can not only enhance user experience but also effectively guide users to delve deeper into reading.The traditional article list may only display titles, publication time, summaries, and other information, making it somewhat monotonous.

2025-11-07

How to convert a timestamp to a specified date format and display it in the AnQiCMS template?

In Anqi CMS template design, we often encounter the need to display timestamp data in a human-readable date format.Whether it is the publication time of the article, the update date of the content, or the record of user activities, this data is usually stored in the database in the form of timestamps.It is particularly important to master how to convert timestamps to the specified date format in templates so that website visitors can clearly and intuitively understand this information.

2025-11-07

How to ensure that custom parameters set in the AnQiCMS backend can be displayed in the front-end template?

The AnQi CMS endows content management with high flexibility, among which the customizable parameter function is the key to meeting the needs of personalized content display.How to accurately display the unique parameters set for content models such as articles, products, or categories on the website front-end template is a concern for many users.This article will detail this process, helping you fully utilize the powerful customization capabilities of Anqi CMS.

2025-11-07

How to implement keyword batch replacement in AnQiCMS and affect the display of front-end content?

It is crucial to maintain the accuracy, timeliness, and brand consistency of content in website operations.Especially when the amount of website content is large, if you need to make global changes to specific keywords or phrases, manual operation will be a huge project that is time-consuming and labor-intensive.AnQiCMS (AnQi CMS) exactly discerned this need, providing a powerful feature named 'Full Website Content Replacement' to help users efficiently manage and update website content, thereby affecting the display effect of front-end content.Why do we need to batch replace keywords? With the development of the enterprise, product updates, or market strategy adjustments

2025-11-07

How to display the number of views and comments on articles in AnQiCMS templates?

In website operation, the number of page views and comments on articles is an important indicator of the popularity of content and user engagement.AnQiCMS provides flexible template tag functions, allowing you to easily display these key data on the website front end, thereby better attracting visitors and enhancing content value.

2025-11-07

How to customize the display of image carousel (Banner) through template tags in AnQiCMS?

AnQiCMS as an efficient and customizable enterprise-level content management system has a significant advantage in the flexibility of content display.For the common picture carousel (Banner) feature on the website, AnQiCMS provides various ways to customize the display through template tags, allowing you to easily achieve diverse Banner display effects according to different page and business needs.

2025-11-07

How to safely output HTML code in AnQiCMS templates without escaping?

When building and managing website content, we often need to display rich text content with specific formats or interactive effects on the page, such as the main body of articles, product descriptions, and even embedded video players or maps.AnQiCMS (AnQiCMS) is an efficient and flexible content management system that, when handling these requirements, defaults to taking an important security measure: escaping the HTML code output in the template.

2025-11-07

How to display user details and user grouping information in the AnQiCMS user group management?

In AnQiCMS, effectively managing users and user groups is a key factor in building personalized websites, implementing membership strategies, and even achieving content monetization.By flexibly using its built-in template tags, we can easily display users' detailed information and their user group information on the website front end, providing a more customized and interactive experience.The "User Group Management and VIP System" feature provided by AnQiCMS allows website operators to divide different user groups according to business needs and define exclusive permission levels for these groups.

2025-11-07