As an experienced website operations expert, I fully understand the key role of an efficient content management system in the success of a website.AnQiCMS (AnQiCMS) provides great convenience for operators with its flexible template engine and rich features.Today, let's delve into a commonly used and key tag in the AnQiCMS template:{% linkList friendLinks %}Especially among themfriendLinksThe data structure represented by the variable, and how to make full use of it to optimize your website.

DecryptionfriendLinksWhat kind of data structure is it?

In Anqi CMS template design, when you see{% linkList friendLinks %}such a tag,friendLinksit is not just a simple string or a single link, but alist (or array) objectIt carries all the friendship link entries configured in the website background, and each entry itself is a structured data block containing the detailed information of the friendship link.

Imagine that in the "Friendship Link Management" module of your website backend, you may have added dozens or even hundreds of friendship links.friendLinksThis variable is equivalent to packaging all visible links on the backend management interface into an ordered collection for front-end templates to call and display as needed.Since it is a list, this means you need to traverse it in a loop to access and render each link one by one.

friendLinksCarrying information in each element.

SincefriendLinksIs a list object, then what specific information does each 'friend link' entry contain? According to the Anqi CMS template tag document, each element in the list can be understood as an object containing the following key fields (or a struct in Go language):

  1. Title(Link Name)This field stores the display text of the friendship link, which is the clickable link text that users see on your website.For example, 'Anqi CMS official website', 'Some technology blog' and so on.It is usually a string type.

  2. Link(Link address)This field saves the actual URL address of the friendship link.When the user clicks the link, the browser will jump to this address.This is also a string type, and is usually a complete URL, such ashttps://en.anqicms.com.

  3. Remark(Link Description)This is an optional field, used to store additional information or remarks about the friendship link.This note may not be displayed directly on the front page, but it can be used for background administrators to classify or record links. Of course, if you need it, you can also display it in the template.

  4. Nofollow(Whether to Add)nofollowAttribute): This is a very important SEO-related field. It is usually a boolean value (or an equivalent number, such as0Indicatesfalse,1IndicatestrueWhenNofollowWith1It means that the friendship link should be added during renderingrel="nofollow"The attribute tells the search engine crawler not to follow this link and not to pass the weight of your website to the target website, which is crucial for managing the SEO impact of external links.

Once you understand these fields, you can clearly know how to proceed fromfriendLinksExtract the required information from the list and present it in your website template.

Practice session: How to use in the templatefriendLinks

MasteredfriendLinksAfter the data structure, how do you show this information in the AnQiCMS template? Since it is a list, we will naturally use the template engine'sforLoop tags. The following is a typical template code example that shows how to traversefriendLinksAnd output each friendship link:

{% linkList friendLinks %}
{% if friendLinks %} {# 建议先判断friendLinks是否存在或不为空 #}
<div class="footer-links">
    <h3>友情链接</h3>
    <ul class="friend-links-list">
        {% for item in friendLinks %} {# 遍历friendLinks列表,每个链接项命名为item #}
        <li>
            <a href="{{ item.Link }}"
               {% if item.Nofollow == 1 %} rel="nofollow"{% endif %} {# 根据Nofollow字段动态添加rel属性 #}
               target="_blank" {# 通常友情链接会设置为新窗口打开 #}
               title="{{ item.Remark|default:item.Title }}" {# 如果Remark存在则作为title,否则使用Title #}>
                {{ item.Title }}
            </a>
        </li>
        {% endfor %}
    </ul>
</div>
{% endif %}
{% endlinkList %}

In this code block:

  • {% linkList friendLinks %}The tag first called the background friendship link data and assigned it tofriendLinksVariable.
  • {% if friendLinks %}It is a good practice to judgefriendLinkswhether it is empty. If there is no configuration of friendship links, the entire block will not be rendered, avoiding unnecessary blank spaces or errors on the page.
  • {% for item in friendLinks %}Looped throughfriendLinksthe list. In each iteration, the current friendship link entry is assigned toitemthis temporary variable.
  • Byitem.Link/item.Title/item.Remarkanditem.NofollowWe can easily access the specific attributes of each link entry.
  • {% if item.Nofollow == 1 %} rel="nofollow"{% endif %}This line of code is particularly important, it dynamically adds attributes to the link based on the backend configurationrel="nofollow"which is crucial for maintaining the SEO health of the website
  • title="{{ item.Remark|default:item.Title }}"and handles it elegantlyRemarkThe field may be empty. If the note does not exist, use the link title as a prompt.

Manage and call friend links in this structured way, not only makes your template code neat and easy to understand, but also greatly improves the efficiency of content updates and maintenance.

Why should we use structured data to manage友情链接 links?

Our company's CMS adopts this structured method (objects in a list) to manage友情链接 links, which has profound operational and technical considerations:

  1. Content and presentation separation: Friend link data (such as URL, title, whether Nofollow) is stored in the background, and how to display (color, font, layout) is controlled by the front-end template.This separation allows website design and content management to be carried out independently, without affecting each other.
  2. convenient for batch management and expansion: When all links are stored in a uniform structure, the backend operations of adding, deleting, modifying, and querying become very efficient.In the future, if it is necessary to add new attributes to the friendship link (such as the link's logo image, category, etc.), it is only necessary to add the corresponding fields in the data structure without modifying the existing logic.
  3. beneficial for SEO strategy implementation:NofollowThe built-in support for attributes allows operation personnel to finely control which links should pass weight and which should not, effectively avoiding SEO negative impacts caused by the abuse of friend links.
  4. Enhance the reusability and maintainability of the templateOnce defined:friendLinksThe data structure, any developer who follows the AnQiCMS template syntax can quickly understand and make template modifications or customizations, reducing the cost of learning and maintenance difficulty.

In short,{% linkList friendLinks %}