In website content creation, we often need to mention website URLs and email addresses in articles, descriptions, or comments.If this information is just plain text, users cannot directly click to jump, which undoubtedly affects user experience and the efficiency of information transmission.AnQiCMS as an efficient content management system, fully considers this requirement and built-in intelligent functions, which can automatically convert URLs and email addresses in plain text into clickable HTML links.
AnQiCMS Automatic link conversion is the core feature:urlizeFilter
AnQiCMS uses a template engine syntax similar to Django,urlizeThe filter is the key to this function. It can intelligently scan text content and identify URLs that start withhttp:///https:///www.even some bare domain names likeanqicms.com)and email address format(for example[email protected])as a string, and automatically wrap it in<a>tags to make them clickable links.
The convenience of this feature is that you do not need to manually write HTML code to create links. Simply pass the plain text content tourlizeFilter, the system will automatically process, greatly improving the efficiency of content editing. In addition,urlizethe filter will also automatically add with care when converting links.rel="nofollow"Properties, this is very helpful for the SEO optimization strategy of the website, especially for managing the weight transfer of external links.
Usage:
In AnQiCMS templates,urlizeFilters through the pipe symbol|Applied to any variable containing text. SinceurlizeThe conversion will generate HTML tags, in order to ensure that these HTML tags can be correctly parsed by the browser rather than displayed as plain text, we usually need to use them in conjunction.safeFilter. Otherwise, you might see something like<a href=\"...\">...</a>such original HTML code.
For example, if you have a variable namedarchive.ContentThe variable stores the article content, which includes plain text URLs and email addresses, and you can use it like this:
<p>{{ archive.Content|urlize|safe }}</p>
This code willarchive.ContentConvert all URLs and email addresses in the text to clickable links and safely render them on the page.
Optimize the display of long links:urlizetruncFilter
对于那些非常长的 URL,如果直接在页面上完整显示,可能会导致排版混乱,影响整体美观。AnQiCMS 也为此提供了 Englishurlizetrunca filter, which inurlizeon the basis of it increased the feature of truncating link text.
urlizetruncAllow you to specify the maximum length of the link text displayed. If the text length of the original URL exceeds this limit, it will be abbreviated after the specified length....Replace the overflow part while maintaining the validity of the link.
Usage:
urlizetruncThe filter accepts a numeric parameter representing the maximum display length of the link text (including ellipsis).
<p>{{ long_description|urlizetrunc:50|safe }}</p>
In the above example,long_descriptionIf any link text exceeds 50 characters, it will be truncated and displayed in English...But the underlying link address is still complete. This is very practical for scenarios that require maintaining the page clean, such as news summaries, product introductions, etc.
Application scenarios and value
These filters can be used at any location in the AnQiCMS template, especially suitable for the following scenarios, bringing practical value to your content operation:
- Article details pageIn displaying the article content, abstract, keywords, and other information, ensure that the links and email addresses included are clickable to enhance the convenience for users to obtain relevant information.
- Category or single page descriptionIn the description text of category introduction, about us and other single-page, it is convenient for users to quickly access related resources or contact information.
- User comments or messages:Automatically processes user-submitted links and emails to enhance interactivity (Note: For user-generated content, it may also require combining with other security filtering measures).
- Custom fieldsIf the content model includes custom text fields that store URLs or email addresses, these filters can also be processed to ensure consistent and complete frontend display effects and functionality.
PassurlizeandurlizetruncFilter, AnQiCMS helps you easily achieve:
- Enhance user experienceUsers do not need to copy and paste, just click to access, reducing the threshold of operation.
- Optimize content displayEspecially:
urlizetruncIt allows long URLs to not disrupt the page layout and keep the interface neat. - Indirectly assist SEO:自动添加的
nofollowThe attribute helps website administrators better control the impact of external links on the site's weight and is one of the standard SEO practices. - Improve operational efficiencyThe content publisher does not need to pay attention to the HTML format of the link, focusing on content creation itself.
Common Questions (FAQ)
1.urlizeandurlizetruncWhat are the main differences between the filters?
urlizeThe filter will convert URLs and email addresses in the text into clickable links, with the link text being the original URL or email address.urlizetruncThen, while converting, you can specify a maximum length. If the original link text exceeds this length, it will be truncated and an ellipsis will be added at the end....This helps to keep the page neat.
2. Why do you need to addurlizeorurlizetruncAfter, what is displayed is HTML code instead of a clickable link?This is usually because you forgot to add at the end of the filter chainsafeFilter. AnQiCMS's template engine defaults to escaping all output content to HTML for security reasons, to prevent cross-site scripting attacks (XSS).urlizeandurlizetruncThe generated is HTML tag, if not appliedsafeFilter, these tags themselves will be escaped to plain text, causing the displayed on the page to be<a href="...">such code.
3.urlizeAutomatically addedrel="nofollow"Can the property be removed or modified?According to AnQiCMS's default design,urlizeThe filter will automatically add to the converted linksrel="nofollow"Property.This is a built-in behavior designed to help websites better manage the SEO impact of external links.Currently, the option to directly remove or modify this property through the template filter itself is not publicly provided.If you have specific requirements, you may need to consider directly manually inserting the HTML link at the time of content publishing, or processing it through other frontend JavaScript methods.