How to automatically add hyperlinks to URLs and email addresses in article content of AnQi CMS?

Calendar 👁️ 66

In content management and website operation, automatically converting URLs and email addresses in text to clickable hyperlinks not only greatly enhances user experience but also optimizes the internal link structure of the website to some extent.For AnQiCMS users, achieving this feature is not through simple backend settings, but through the specific 'filter' provided by its powerful template engine.This design approach gives website owners great flexibility and control, allowing them to finely manage the generation of links according to the needs of different content areas.

Understand the automatic link mechanism of AnQiCMS

One of AnQiCMS's core strengths is its high-performance template engine, which draws on the syntax of Django templates.The feature of automatically adding hyperlinks to URLs and email addresses in this architecture is not executed immediately when you save the article content.On the contrary, it is dynamically completed by applying specific template filters when the content is 'rendered' (i.e., displayed) on the front-end page.

This means that when you edit articles in the background, even if you enter them directlywww.anqicms.comor[email protected]Such plain text, AnQiCMS will not store it in the database either<a>Tags. The benefit of this is that it maintains the purity of the content, and it hands over the rendering logic of the link to the front-end template, thus allowing different link processing rules to be applied in different pages or content blocks, such as where links are needed and where they are not.

Core function:urlizeFilter

To implement automatic hyperlinks for URLs and email addresses on the front-end page, AnQiCMS provides a namedurlizeThe built-in filter. This filter is specifically used to identify URLs in text (including those withouthttp://orhttps://such aswww.example.comandexample.com) and email addresses, and wrap them automatically in<a>Tags within. To comply with SEO**practices,urlizeThe filter will also automatically add to these generated linksrel="nofollow"attributes, which help inform search engines that these links do not pass weight, and avoid unnecessary SEO risks.

For example, if you include the following text in the article content field (usuallyarchive.Content) as follows:

欢迎访问 AnQiCMS 官方网站:https://en.anqicms.com,
或者通过邮箱联系我们:[email protected],
我们还提供文档:www.kandaoni.com。

If you output directly in your template file,{{ archive.Content }}These URLs and email addresses will still be plain text. But if you applyurlizea filter like this:

{{ archive.Content|urlize|safe }}

Then when the page loads, this content will be rendered as:

欢迎访问 AnQiCMS 官方网站:<a href="https://en.anqicms.com" rel="nofollow">https://en.anqicms.com</a>,
或者通过邮箱联系我们:<a href="mailto:[email protected]" rel="nofollow">[email protected]</a>,
我们还提供文档:<a href="http://www.kandaoni.com" rel="nofollow">www.kandaoni.com</a>。

Please note that an additional|safefilter was used. This is becauseurlizeThe filter will convert plain text to text containing HTML tags(<a>The text, while AnQiCMS template engine defaults to escaping all output content for security reasons to prevent XSS attacks. If there is no|safeYour link may be displayed as plain text.&lt;a href=&quot;...Therefore, when you are sure.urlizeWhen the content generated by the filter is safe and needs to display HTML tags, be sure to use them in conjunction.|safefilter usage.

urlizeThe filter also supports an optional parameter to control whether the link text is escaped. By default, the link text is kept unchanged. If it is set totrueIf the special characters in the link text are escaped; if set tofalse(or not set), no additional escaping will be performed on the link text. Usually when used in article content, you would want to retain the original text display, so it is usually not necessary to set this parameter or set it tofalse. For example:

{# 链接文本不会被转义,显示为原始URL或邮箱 #}
{{ archive.Content|urlize:false|safe }}

Advanced Application:urlizetruncFilter

For scenarios that may contain long URLs, AnQiCMS also providesurlizetrunca filter. Its function is tourlizeSimilar, but it adds an additional feature: you can specify a numeric parameter to truncate the text displayed in the hyperlink. When the length of the URL exceeds this specified value, the excess part will be...Replace it, thus maintaining the page layout.

For example, if you have a very long URL:https://en.anqicms.com/this-is-a-very-very-long-article-title-that-results-in-a-very-long-url-example.htmlIf you want to limit the display length to 20 characters, you can use it like thisurlizetrunc:

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

This code may render the above long URL as:

<a href="https://en.anqicms.com/this-is-a-very-very-long-article-title-that-results-in-a-very-long-url-example.html" rel="nofollow">https://www.anqic...</a>

This is especially useful in limited space areas such as news lists, article summaries, or comment sections, where it can provide link functionality without destroying the visual balance of the page.

How to effectively utilize in content

In order to effectively utilize these automatic hyperlink functions on your AnQiCMS website, you need to edit the website template files. Usually, the article detail page (such asarchive/detail.html) and single page detail page (such aspage/detail.html**The output part of the content in**)

Find the tags (such as**) that display the article or page content in your template.{{ archive.Content|safe }}or{{ page.Content|safe }}),then change it to:“

{# 为文章内容自动添加超链接 #}
{% archiveDetail articleContent with name="Content" %}
    {{ articleContent|urlize|safe }}
{% endarchiveDetail %}

{# 或者为单页内容自动添加超链接 #}
{% pageDetail pageContent with name="Content" %}
    {{ pageContent|urlize|safe }}
{% endpageDetail %}

If you want to truncate the link text:“

{# 为文章内容自动添加超链接并截断链接文本至40个字符 #}
{% archiveDetail articleContent with name="Content" %}
    {{ articleContent|urlizetrunc:40|safe }}
{% endarchiveDetail %}

In this way, all the articles and page content on your website, as long as it contains recognizable URLs or email addresses, will be automatically converted into clickable hyperlinks on the front-end, greatly enhancing the user experience and accessibility of information.

Points to note

  • change at the template levelRemember, these are all template-level operations. If you are not familiar with the template file structure of AnQiCMS or the GoLang template engine, it is recommended to seek professional help or carefully read the AnQiCMS template development document to avoid unnecessary errors.
  • |safefilter is crucialWhen you output content that may contain HTML tags (such as byurlizeorurlizetruncGenerated<a>tags) be sure to use|safeA filter to ensure that HTML code is parsed correctly by the browser and not displayed as plain text.
  • Flexibility and controlThis dynamic rendering method allows you to precisely control which content areas need to be automatically linked, as well as the display style of the links, thereby better serving your website's operational strategy.

By reasonably utilizing the AnQiCMS providedurlizeandurlizetruncFilter, you can make your website content more interactive while maintaining SEO-friendly and providing a smoother browsing experience for users.

Frequently Asked Questions (FAQ)

1. Why does the URL I input in the background while editing an article automatically become a hyperlink on the front end? Where is this set?AnQiCMS does not set a global 'auto-link' switch in the background.This feature is implemented through a specific "filter" in the front-end template file.When your article content is displayed on the front page, if the template has applied to the contenturlizeorurlizetruncA filter that dynamically recognizes URLs and email addresses in text and converts them into clickable hyperlinks.

2. Why does the URL show up after I follow the tutorial?<a href="...">Such plain text, not clickable links?This is usually because you have applied in the templateurlizeorurlizetruncAfter filtering, forget to add after it|safeThe filter. The AnQiCMS template engine, to prevent potential security risks (such as XSS attacks), defaults to escaping all output HTML tags.|safeThe filter tells the template engine that this content is safe, does not require escaping, and thus allows the browser to correctly parse and display it as a clickable hyperlink.

3. Will automatically added hyperlinks affect the SEO of the website?AnQiCMS'urlizeandurlizetruncThe filter automatically adds hyperlinks to the links generated.rel="nofollow"The attribute tells the search engine that these links should not pass 'link juice', that is, they should not be counted in the search engine's ranking weight.This is generally considered a good SEO practice, especially when generating links automatically or when the link target is not the core content of the website, which can avoid unnecessary SEO risks and maintain the overall health of the website's link structure.

Related articles

How to display multi-language switch links and the current language identifier in Anqi CMS?

In AnQi CMS, implementing multi-language switch links and current language identification is a very practical feature that can help your website easily face global users and enhance the internationalization level of your website.Aqicms provides intuitive and powerful template tags, allowing you to flexibly display these elements on the website front end. ### One, understand the multilingual capabilities of Anqicms Anqicms has considered the needs of multilingual sites from the very beginning and provides comprehensive multilingual content management support.This means you can create and manage independent content for different languages in the background, such as articles

2025-11-08

How to display a custom prompt message during the website shutdown maintenance of AnQi CMS?

During the operation of the website, we sometimes have to temporarily close the website for maintenance in order to upgrade the system, optimize data, or adjust functions.How to clearly and friendly convey this status to visitors, avoiding confusion or loss of users, is particularly important.Safe CMS provides a set of built-in solutions that allow you to easily customize the prompt information for your website during maintenance shutdown. ### Understanding the shutdown mechanism of AnQi CMS The shutdown feature of AnQi CMS is designed to be very intuitive and flexible.When you enable the closed site mode, the system will automatically intercept all access requests to the website content

2025-11-08

How to reference common code snippets (such as headers and footers) in Anqi CMS templates to unify page display?

It is crucial to maintain consistency in the display of web pages during website operations.A unified website appearance can not only enhance brand professionalism but also optimize user experience.AnqiCMS provides a powerful and flexible template mechanism, allowing us to efficiently manage common website elements such as headers and footers, thus avoiding repetitive code writing and ensuring the consistency of the entire site style.The AnqiCMS template system draws on the syntax of the Django template engine, with the core idea being that developers can define reusable code snippets and page skeletons

2025-11-08

How to configure content automatic external link filtering in Anqi CMS and how it affects the display of front-end links?

In website content operation, the management of external links is a vital aspect that cannot be ignored.It not only relates to user experience, but also directly affects the website's search engine optimization (SEO) performance.AnQi CMS knows this and therefore provides a flexible and practical external link handling mechanism to help content operators efficiently manage external links in articles.Where is the AnQi CMS external link configuration? AnQi CMS provides a very convenient function to handle external link issues, and you can easily configure it in the system background.The specific path is: log in to your AnQi CMS backend

2025-11-08

How to truncate a long string and display an ellipsis in AnQi CMS templates?

The flexibility of content display is crucial in the template making process of Anqi CMS.When it is necessary to display a long text within a limited space, such as an article abstract, product description, or brief introduction, truncating the strings with an ellipsis is a common optimization method. It can effectively maintain the neat layout of the page and guide users to click and view the full content.AnQi CMS is developed based on Go language, its template engine syntax is similar to Django, and it provides powerful filter (filters) functions that can easily meet this requirement.### Skillfully Utilize Filters

2025-11-08

How can AnQi CMS templates inherit parent templates and rewrite specific block content to customize display?

In Anqi CMS, the template system provides a powerful and flexible mechanism that allows users to efficiently customize the layout and content display of the website.Among them, "inheriting the parent template and rewriting specific block content" is a key function to achieve personalized design and maintain consistency with the overall style of the website. ### Core Concept: Say goodbye to repetition, embrace inheritance Imagine that the header, footer, sidebar, and other elements of a website are fixed and unchanged on almost every page. If there is no template inheritance mechanism, we may need to repeat this common code in each page template, which increases the difficulty of maintenance

2025-11-08

How can AnQi CMS use the 'time factor' feature to display future published content?

How to efficiently and strategically publish content in today's fast-paced content environment is a question that every content operator is thinking about.Maintain the consistency and foresight of content publication, which can not only enhance the user experience but also effectively promote brand communication and search engine optimization.AnQi CMS deeply understands this, and its 'Time Factor' feature was born for this very purpose, providing content creators and operation teams with a precise tool to control the timing of content release.## Precise Planning: The Foundation of Content Operation We have all faced such a situation: writing an精心 prepared article

2025-11-08

Does AnQi CMS provide an integrated JS statistics code calling tag for easy display on the page?

When using AnQiCMS, many users are concerned about how to conveniently integrate third-party JavaScript statistical codes into web pages, such as Baidu Statistics, Google Analytics, and so on.About this, AnQiCMS indeed provides built-in mechanisms and flexible template tags, allowing you to easily call and display these statistics codes on your website.### Using built-in JS code to call tags AnQiCMS to meet the needs of website operators to integrate third-party scripts

2025-11-08