In today's website operation, user experience has become a key indicator of whether a website is successful or not.A smooth browsing experience, clear information display, and convenient interaction can significantly enhance user satisfaction.AnQiCMS (AnQiCMS) is a powerful content management system that provides many tools to help operators optimize their websites, and by cleverly using template tags and filters, they can achieve twice the results with half the effort.

Today, we will focus on a seemingly simple but highly potential user experience improvement feature in Anq CMS: how to apply througharchiveDetailtags to document content inurlizeFilter. It is not just a technical implementation, but also a strategy to make your content more 'friendly'.

UnderstandingarchiveDetailTag: The core of content.

Let's quickly review firstarchiveDetailLabel. In the Anqi CMS template system, when you need to display the details of a document (whether it is an article, product details, or other custom model content),archiveDetailTags are your helpful assistant. It can extract various fields of the document according to the current page or specified ID, such as the title (Title), Description (Description) content (Content) as well as the thumbnail (Thumb) and so on.

For example, on the document detail page, you would usually use it to retrieve the main content of the article:

{# 假设当前页面就是一篇文档的详情页 #}
<div>
    <h1>{{ archive.Title }}</h1>
    <div class="article-body">
        {{ archive.Content|safe }}
    </div>
</div>

Here{{ archive.Content|safe }}That is the way to retrieve and display the main content of the document. You might notice|safeThis filter is crucial here becausearchive.Contentusually contains HTML code generated by a rich text editor,|safeTell the template engine that this content is safe HTML, it does not need to be escaped, and can be rendered directly.

RevelationurlizeFilter: Make the link 'alive'

Now, the key point comes. Imagine that the author may have directly pasted a URL in your article content, such as “Please visit our website:https://en.anqicms.comTo get more information. If displayed directly, this URL is just plain text, and the user needs to manually copy and paste it to access.This undoubtedly increases the user's operational cost and reduces the experience.

urlizeThe filter is designed to solve this pain point. Its function isAutomatically identify URLs and email addresses in text and convert them to clickable HTML<a>Tag. It also defaults to adding attributes to these automatically generated linksrel="nofollow"which is a good default behavior for the SEO processing of external links

Whenurlizeencountering likehttps://en.anqicms.comWhen such text is encountered, it will intelligently wrap it as:<a href="https://en.anqicms.com" rel="nofollow">https://en.anqicms.com</a>.

Practical application: Make your document content come to life

InarchiveDetailApply within the obtained document contenturlizeThe filter is very simple, you just need to add it toContentAfter the field:

<div class="article-body">
    {{ archive.Content|urlize|safe }}
</div>

Note here:|urlizePlaced before:|safeThis is because:urlizeThe filter will generate HTML<a>tags, while|safeEnsure that these generated HTML can be correctly parsed and displayed by the browser, rather than being escaped as plain text. If the order is reversed,urlizeThe generated HTML may be escaped again, causing links to become unclickable.

User experience improvement points:

  1. Seamless navigation:Users do not need to manually copy and paste, just click to jump, which greatly simplifies the operation process.
  2. Visual clarity:Links will display in the browser's default link style (usually blue with an underline), allowing users to easily identify clickable elements.
  3. Reduce editing burden:For content editors, they do not need to manually insert links in the rich text editor. They just need to type the URL, and the system can automatically handle it, improving work efficiency and avoiding link errors caused by manual operations.

Handle long links:urlizetruncusefulness

Sometimes, very long URLs may appear in the article, which may affect the aesthetics of the page. Anqi CMS also providesurlizetruncFilter, it isurlizeThe feature of truncating display has been added. You can specify a length, and the link text will be truncated if it exceeds this length, followed by an ellipsis...The actual link address does not change.

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

<div class="article-body">
    {{ archive.Content|urlizetrunc:20|safe }}
</div>

In this way, a long link likehttps://en.anqicms.com/documentation/how-to-use-urlize-filter-in-anqicms-templates.htmlmay be displayed ashttps://www.anqicms.co...It maintains the validity of the link and improves the visual cleanliness.

The extension of the operation value.

urlizeThe filter is not just a technical optimization, it also brings tangible value to website operations:

  • Improve user retention:Convenient interaction will encourage users to spend more time on the website, exploring more content.
  • Optimize the content publishing process:Content creators can focus on the content itself, without being distracted by link formatting, ensuring publishing efficiency.
  • Hidden SEO advantages:Automatically addednofollowProperties help control the impact of external links on website authority and follow search engine practices.

By adding inarchiveDetailThe tag applies to the content of the document obtained.urlizeFilter, you can achieve a dual improvement in user experience and content management efficiency with the least changes, making your Anqi CMS website more attractive.

Frequently Asked Questions (FAQ)

Q1: Why when usingurlizeAfter that, the link displays the original text instead of a clickable link?A1: This is usually because you forgot tourlizeAdd after the filter|safeFilter. The Anqi CMS defaults to HTML escaping all output content for security reasons.urlizeGenerated by the filter<a>The tag itself is HTML code, if not|safeThese HTML codes will be displayed as escaped text, causing links to not be clickable. The correct usage is{{ archive.Content|urlize|safe }}.

Q2:urlizeThe filter recognizes what types of links? Does it also work for email addresses?A2:urlizeThe filter can recognize common URL formats such ashttp:///https:///www.addresses starting with) and email addresses. For example,[email protected]It will be converted intomailto:[email protected]Clickable links, greatly facilitating users to contact you.

Q3:urlizeCan the automatically generated links be customized?relproperties, for example, I want some internal links not to havenofollow?A3:urlizeThe filter will automatically add to all links generatedrel="nofollow"Property. Currently, there is no direct parameter at the filter level to cancel or modify this default behavior. If you need to refine the link for a specific purpose,relAttribute control (for example, make sure internal links do notnofollow), and it is recommended to manually use the rich text editor's link feature to insert HTML when editing content<a>tags instead of relying onurlizeAutomatically convert, so you can fully customize the link attributes.