{% linkList friendLinks %}English translation: Especially amongfriendLinksThe data structure represented by the variable and how to make full use of it to optimize your website.
DecryptionfriendLinksEnglish translation: What kind of data structure is it?
In the template design of AnQi CMS, when you see{% linkList friendLinks %}such tags are,friendLinksnot 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 that contains detailed information about the friendship link.
Imagine that your website's "Friendship Link Management" module may have added dozens, even hundreds, of friendship links.friendLinksThis variable is equivalent to packaging all visible links on the backend management interface into an ordered collection, for the frontend template to call and display as needed.Since it is a list, this means you need to iterate through it in a loop to access and render each link in the list.
friendLinksEach element carries information
SincefriendLinksis a list object, then what specific information does each 'friend link' entry in the list contain? According to the template tag document of Anqi CMS, each element in the list can be understood as an object containing the following key fields (or called a struct in Go language):
Title(Link Name)This field stores the display text of the friend link, which is the clickable link text that users see on your website.For example, "Anqi CMS official websiteIt is usually a string type.Link(Link address)This field saves the actual URL address pointed to by the friendship link.When the user clicks the link, the browser will jump to this address.https://en.anqicms.com.Remark(Link Note)This is an optional field, used to store additional notes or remarks about the friendship link.This note may not be displayed directly on the front page, but it can be used by backend administrators to classify or record links. Of course, if you need, it can also be displayed in the template.Nofollow(Is Added)nofollowProperty): This is a very important SEO-related field. It is usually a boolean value (or an equivalent number, such as0representingfalse,1representingtrue). WhenNofollowresponse for1When, it means that this link should be added when renderedrel="nofollow"Property.This attribute tells the search engine crawler not to track 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.
After understanding these fields, you can clearly know how to get fromfriendLinksExtract the required information from the list and present it in your website template.
Practical Exercise: How to usefriendLinks
MasteredfriendLinksThe data structure and how to display this information in AnQiCMS templates? Since it is a list, we will naturally use the template engine'sforLoop tags. Here is a typical template code example that shows how to iteratefriendLinksand output each 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 calls the background link data and assigns it tofriendLinksa variable.{% if friendLinks %}is a good practice for judgmentfriendLinkswhether it is empty. If there is no configuration of friendship link, the entire block will not be rendered, to avoid unnecessary blank or error on the page.{% for item in friendLinks %}The loop traversedfriendLinksthe list. In each iteration, the current friend link entry is assigned toitemthis temporary variable.- Pass
item.Link/item.Title/item.Remarkanditem.Nofollow, we can easily access the specific properties of each link entry. {% if item.Nofollow == 1 %} rel="nofollow"{% endif %}This line of code is particularly important, it dynamically adds links based on backend configuration.rel="nofollow"Properties, which is crucial for maintaining the SEO health of the website.title="{{ item.Remark|default:item.Title }}"in an elegant manner.RemarkField may be empty. If the note does not exist, use the link title as a prompt.
Managing and calling 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 structured data be used to manage friend links?
The AnQi CMS adopts this structured approach (objects in the list) to manage friend links, which has profound operational and technical considerations:
- Content and presentation are separated:Friend link data (such as URL, title, whether Nofollow) is stored in the backend, and how to display (color, font, layout) is controlled by the frontend template.This separation allows the website design and content management to be carried out independently, without affecting each other.
- Easy for batch management and expansionWhen all links are stored in a unified structure, the background operations of add, delete, modify, and query become very efficient.If in the future it is necessary to add new attributes to the friend 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.
- Beneficial for SEO strategy implementation:
NofollowThe built-in support for properties allows operation personnel to finely control which links should pass weight and which should not, effectively avoiding negative SEO impacts caused by excessive use of friendship links. - Increase 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 learning cost and maintenance difficulty.
In short,{% linkList friendLinks %}