Will the link generated by the `urlize` filter include the original URL's `title` or `alt` attribute?

Used in the template of AnQi CMSurlizeA filter that can effectively convert URL addresses in text content into clickable HTML links. Many users, while using this convenient feature, may also be concerned about whether the generated links will automatically includetitleoraltProperties, to enhance user experience or optimize SEO.

urlizeThe core function and actual performance of the filter

When using the template of Anqi CMS for content presentation,urlizeA filter is a very practical tool, located in the "More Filters" category. Its main function is to automatically convert recognized URLs (including plain text URLs and email addresses) in the text content into clickable links.<a>Label.

For the common concerns of everyoneurlizeWill the filter automatically add properties to the generated linkstitleoraltThe answer iswill not.

According to the document description of the Anqi CMSurlizeThe actual function of the filter, which will automatically include in the conversion processhrefan attribute to specify the link target, and is added by defaultrel="nofollow"an attribute to indicate to the search engine that the link does not pass weight. In addition,urlizeSupports a boolean parameter to control whether the link content is HTML-escaped, but this is limited to the processing of the link text itself, and it is not related to the automatic addition of properties.titleoraltThe automatic addition of properties.

For example, when we include a URL in a text例如访问我们的网站 www.anqicms.com 或者通过邮件联系我们 [email protected]PassurlizeAfter filtering, it generates an HTML structure similar to the following:

例如访问我们的网站 <a href="http://www.anqicms.com" rel="nofollow">www.anqicms.com</a> 或者通过邮件联系我们 <a href="mailto:[email protected]">[email protected]</a>。

As you can see,titleandaltAttributes are not generated automatically.altAttributes are usually used for<img>Tag, whileurlizeThe filter mainly handles the conversion of URLs in text.<a>Tag, so it is inherently related toaltThe application scenario of the attribute does not match.titleThe attribute is applicable to<a>Tags, but noturlizealso does not include the automatic conversion logic.

Whyurlizeautomatically addtitleoraltproperties?

Understandingurlizethe design intention of the filter, which helps explain why it does not automatically addtitleoraltProperty. As a general text to link conversion tool,urlizeit is designed to be lightweight and automated.titleProperty is usually used to provide additional information or description for links,altThe attribute is the alternative text for the image content, both of which are strongly dependent on the specific context and content of the link or image.

urlizeThe filter cannot intelligently infer appropriate values from a normal text URL.titleoraltIf a uniform value is强制添加titlemay lead to the generation of content that is semantically inaccurate, and even produce misleading information, for example, all links use "click here" astitleThis is not beneficial for SEO nor for user experience.

Therefore, AanQi CMS leaves these attributes that require specific contextual information to be determined to the template designer to control according to actual needs, ensuring the accuracy and flexibility of the output content.

If neededtitleoraltHow should the property be handled?

AlthoughurlizeThe filter itself does not provide automatic additiontitleoraltThe function of the attribute, but when you indeed need these attributes to enhance the semanticization, SEO, or accessibility of the link, Anqi CMS provides a flexible template mechanism to achieve this.

The most direct method is to avoid usingtitleoraltin the contexturlizeInstead of using a filter, construct it directly in the template<a>tags. You can make use of various tags provided by the Anqi CMS (such asarchiveDetail/categoryDetailTo get dynamic content, assign it totitleoraltproperties.

For example, if you want the article title link to havetitleproperties, you can achieve it like this:

{# 假设在一个文章列表中,我们希望文章标题链接具有title属性 #}
{% archiveList archives with type="list" limit="5" %}
    {% for item in archives %}
        <div>
            {# 直接构造<a>标签,并使用item.Title作为title属性内容 #}
            <a href="{{ item.Link }}" title="{{ item.Title }} - 查看详情">{{ item.Title }}</a>
            
            {# 如果是图片链接,可以这样添加alt属性 #}
            {% if item.Logo %}
                <img src="{{ item.Logo }}" alt="{{ item.Title }}的封面图" />
            {% endif %}
        </div>
    {% endfor %}
{% endarchiveList %}

This way, you can control preciselytitleandaltThe content of the attribute should be closely related to the context of the page or content, thus better serving user experience, search engine optimization, and the accessibility of the website.

In short, the Anqi CMS isurlizeFilter is an efficient text-to-link tool, but it focuses on generality and automation and does not automatically fill intitleoralt【en】Properties. If you have specific requirements for these properties, it is recommended to utilize the powerful template functions of Anqi CMS to manually construct<a>Label and dynamically bind content to ensure accurate content delivery and **SEO performance.


Common Questions (FAQ)

  1. urlizeThe links generated by the filter will be addedtarget="_blank"Should the link open in a new window?Answer: No.urlizeFilter defaults to only addhrefandrel="nofollow"properties. If you need to link in a new window, you need to manually construct<a>the tag and addtarget="_blank"properties.

  2. I hopeurlizeThe link generated by the filter can pass SEO weight, how to disable itrel="nofollow"properties?Answer:urlizeThe filter defaults to addingrel="nofollow"This means it does not pass SEO weight. BecauseurlizeThe filter does not provide parameters to controlnofollowProperty addition and deletion, you cannot use it if you need to pass link weighturlizeInstead, you should manually build it in the template<a>Labels, make sure not to addrel="nofollow".

  3. urlizeandurlizetruncWhat are the differences between filters?Answer: `urlize