In the daily operation of AnQi CMS, keywords are undoubtedly the core of content strategy.Whether it is to help users find your website through a search engine or to enhance the relevance and user experience of in-site content, 'keywords' play a vital role.The Anqi CMS provides a powerful 'keyword library management' feature, helping us to centrally manage and optimize these valuable words.How can the keywords input by the background be implemented in the front-end template for more flexible, intelligent automatic processing and display?This requires us to cleverly combine the template engine'ssplitfilter.
The importance of keywords in Anqi CMS
AnQi CMS is a content management system designed specifically for small and medium-sized enterprises and content operation teams, providing many conveniences in SEO optimization.Among them, the 'Keyword Library Management' function is a major highlight.It is not just a simple list of vocabulary, but also a strategic center.Through it, we can:
- Centralized management: Store all core keywords, long-tail keywords, and business-related vocabulary uniformly for easy search and reuse.
- Optimize contentWhen publishing articles, products, or single-page websites, you can quickly select appropriate keywords from the keyword library to associate them, ensuring that the content revolves around the core theme and enhances SEO effectiveness.
- Auxiliary StrategyCombining the advanced features of Anqi CMS such as 'Keyword Automatic Expansion' and 'Article Collection Based on Keywords' (as mentioned in the historical update log), the keyword library can further unleash its automation advantages, providing endless inspiration and materials for content creation.
We usually add English commas when adding keywords to articles in the background,The form of separating and entering multiple keywords at one time, such as “AnQi CMS, Content Management, SEO Optimization”. However, in the front-end template, if you want to extract these keywords individually, such as adding a link to each keyword or applying different styles, then a seemingly simple but powerful tool comes into play, that is the AnQi CMS template engine in thesplitfilter.
splitThe filter: a bridge between the backend and frontend
We input the keyword, which is often stored in a complete string form in the database.For example, a keyword field of an article may contain "SEO optimization, website operation, content marketing".To turn them into independent, operable elements on the front end, you first need a 'cutting' action.splitThe filter is exactly for this.
Its basic function is to split a string into an array of strings according to the delimiter we specify. For example,"SEO优化, 网站运营, 内容营销"|split:", "This operation will split this long string into an array containing three elements:["SEO优化", "网站运营", "内容营销"]Once we have this array, we can individually traverse and process each keyword in the template.
How to implement automatic extraction and processing of keywords
Let's take a step-by-step look at how to make use ofsplitthe filter, in conjunction with the keyword library management function, to achieve the intelligent extraction and processing of keywords.
Step 1: Build and maintain your keyword library
First, make sure your keyword library is rich and accurate. You can enrich it in the following ways:
- Add manuallyIn AnQi CMS backend, under "Function Management" -> "Keyword Library Management", add your core keywords one by one.
- Batch importIf you already have a large list of keywords, you can quickly import them into the keyword library through the batch import function in the background.
- Automatic keyword expansionUsing the "Keyword Auto-Expansion" feature built into AnQi CMS, the system will intelligently expand more relevant terms for you based on existing keywords, further enriching your keyword resources.
Second step: Empower content with keywords
When editing an article, product, or single-page, you need to associate the keywords in the keyword library with specific content.In the "Add Document" or "Edit Document" interface, find the "Document Keywords" field.You can do:
- Select from keyword libraryClick the select button, pick the appropriate words from your keyword library.
- Manual inputIf the library does not contain the keyword you want, you can also enter it manually,Be sure to use English commas
,to separate different keywords, this issplitThe basis that the filter can correctly identify.
After the content is published, these keywords will be stored in the article in the form of a comma-separated stringKeywordsin the field, waiting for the call of the front-end template
Step 3: Use flexibly in the front-end templatesplitFilter
Now, we come to the front-end template, such as the article detail page(archive_detail.html)。Assuming we want to display a row of clickable keyword tags below the article title:
{# 获取当前文章的关键词字符串 #}
{% archiveDetail keywordsString with name="Keywords" %}
{% if keywordsString %}
{# 使用split过滤器将关键词字符串切割成数组,注意分隔符是", "(逗号加一个空格)#}
{% set keywordArray = keywordsString|split:", " %}
<div class="article-keywords">
<i class="fas fa-tags"></i>
{% for keyword in keywordArray %}
<a href="/tag/{{ keyword|urlencode }}" class="keyword-tag">{{ keyword }}</a>
{% endfor %}
</div>
{% endif %}
In the code above:
{% archiveDetail keywordsString with name="Keywords" %}This line of code retrieves the details of the current article.Keywordsand assigns the value of the field tokeywordsStringVariable.{% set keywordArray = keywordsString|split:", " %}This is the core step,splitFilter appears. It willkeywordsString(For example,", "to generate a namedkeywordArrayarray.{% for keyword in keywordArray %}We useforLoop throughkeywordArrayeach keyword in it.<a href="/tag/{{ keyword|urlencode }}" class="keyword-tag">{{ keyword }}</a>In the loop, we dynamically generate links for each keyword, pointing to the tag page of Anqi CMS (assuming the tag URL structure is/tag/你的关键词), and appliedurlencodeThe filter ensures that the keywords are safe in the URL.
This, whether you manually enter the keywords or select them from the keyword library, they can be automatically parsed on the front end and displayed in a beautiful and practical tag form.
Advanced Application:splitCombination of filters with other filters
splitCombination of filters with other template filters can achieve more complex automation processing:
- Keyword deduplication: Although
splitThis feature does not provide deduplication, but after being cut into an array, you can implement deduplication in the array processing logic (usually in the backend controller or through JS on the frontend, direct deduplication at the template layer is relatively complex).But on display, if there are duplicate keywords, it can be allowed, as this often represents the importance of the word. - Keyword countingIf you want to know how many times a specific keyword appears in the article keyword list, you can first
splitIt into an array, then combinecountFilter (althoughcountThe filter is usually used to calculate the number of occurrences of a specific element in a string or array, but for an exact match within an array, it can be used directly). - Keyword replacement or modification: When the keyword is
splitAfter becoming an array, if needed