In website content operation, the page's 'Title', 'Keywords', and 'Description', which is also known as TDK, plays a crucial role in Search Engine Optimization (SEO).A well-structured and brand-identifiable page title that not only helps search engines better understand the content of the page but also attracts users' attention in search results.Auto CMS (AutoCMS) provides a flexible template engine, allowing us to finely control these key information.

This article will focus on how to巧妙地运用template filters in Anqi CMSaddEnglish translation: Adds brand name or a fixed suffix dynamically to the page title to ensure consistency in brand image and enhance overall SEO.

Understanding the TDK management mechanism of AnQin CMS

In the Aanqi CMS, TDK is usually managed through the SEO settings of the background editing page.Whether it is article details, category list, or single page, we can set SEO titles, keywords, and descriptions for them individually during editing.tdkTags are used to call this information. For example, in<head>Area, we commonly use the following code to display the page title:

<title>{% tdk with name="Title" %}</title>

This code will directly output the current page title set in the background.However, sometimes we want all page titles to be unified with the company's brand name, or a specific suffix, such as “ - Your Brand Name” or “ | Focused on content marketing”.If each page is added manually, it not only requires a lot of work, but is also prone to errors, and it will be very cumbersome to make changes once the brand name needs to be updated.At this moment, dynamically adding this information is particularly important.

addFilter: The Magic Tool for Text Concatenation

The template engine of Anqi CMS supports various filters, among whichaddFilters are powerful tools for string concatenation and numeric addition. Their basic syntax is very intuitive:{{ obj|add:obj2 }}). Whenobjandobj2When all are strings, they are concatenated; when they are numbers, they are added together. It is this ability to concatenate strings thataddFilter is an ideal choice for dynamically constructing page titles.

Dynamically add brand names or fixed suffixes to page titles.

Now, let's see how to make use ofaddFilter dynamically adds brand name or fixed suffix to the page title.

Method one: Add a fixed brand name or suffix

Assuming we want all page titles to end with “ | Your brand name”. We can directly use this fixed text asaddthe parameter of the filter.

Firstly,tdkTag gets the main title of the current page. Then,addthe filter is concatenated with the suffix we set.

<title>{% tdk with name="Title" %}|add:" | 您的品牌名称" %}</title>

The meaning of this code is: get the main title of the current page.TitleEnglish: Then add the string “ | Your Brand Name” at the end of this title.

Method two: Dynamically retrieve the brand name from the system settings.

To better manage brand names, Anqi CMS usually allows us to define a website name (SiteName) or customize a brand parameter in the "Global Feature Settings". We can make use ofsystemLabel to get these global configurations.

Suppose we set the 'Website Name' to 'AnQiCMS Content Management System' in the 'Global Feature Settings' on the backend.

We can do it like this<title>the label useaddFilter:

<title>{% tdk with name="Title" %}|add:" - " |add:{% system with name="SiteName" %}</title>

Here we used it twiceaddThe filter. The first time, we concatenate the main title of the page with the separator “-”, and the second time, we concatenate the result with thesystemThe "website name" obtained by label retrieval is concatenated.So, no matter what the main title of the page is, it will ultimately end with “ - AnQiCMS Content Management System”.

For example, if the title of your article is "AnQiCMS Quick Start", the final page title will be "AnQiCMS Quick Start - AnQiCMS Content Management System".

Method three: usingtdkLabel built-insiteNameProperty (convenient but less flexible)

Actually, Anqi CMS'stdkLabel has a built-in for page titlesiteNameProperties, it can directly implement the function of adding the website name as a suffix.

<title>{% tdk with name="Title" siteName=true %}</title>

WhensiteName=truewhentdkThe label will automatically obtain the "Website Name" from the "Global Function Settings" on the backend and append it as a suffix to the page title. The default separator is " - ". This method is very convenient, but if you need to customize the separator, add text that is not the website name, or want to place the brand name at the beginning of the title, thenaddThe filter will provide greater flexibility.

Practical recommendations and **location

To ensure that the brand name or suffix can be applied to all pages, it is recommended that the following content be includedaddFilters<title>The code is placed in the common header file of the template, for exampletemplate/你的模板目录/bash.htmlortemplate/你的模板目录/partial/header.htmlThese files are usuallyextendsorincludeto other page templates, so that you can modify and apply them to the entire site at once.

When performing this operation, please pay close attention to the SEO effect.The brand name or suffix added dynamically should be short and clear, and avoid overloading keywords to prevent affecting user experience and the judgment of search engines on page titles.Ensure that the combined title length is moderate to display completely in search results.

Common Questions and Answers (FAQ)

Q1:addFilter can only concatenate strings, can it perform numeric operations?

Yes,addFilter can be used for both string concatenation and numeric addition. WhenaddThe filter performs addition on two numeric values.When at least one value is of string type, it will attempt to convert all values to strings and concatenate them.Therefore, in the scenario of dynamically adding brand names, it will concatenate the page title (string) with the brand name (string).

Q2: BesidesTitleI can also use it in the TDK'sKeywordsorDescriptioninaddDo you want to filter to add content dynamically?

Of course you can.addThe filter also applies toKeywordsandDescriptionfields. For example, you can add some common brand keywords after the keywords on the page:<meta name="keywords" content="{% tdk with name="Keywords" %}|add:",安企CMS,内容管理系统" %}">Or add a unified lead-in in the description:<meta name="description" content="{% tdk with name="Description" %}|add:" 立即了解更多安企CMS功能!" %}">However, please note the word limit and relevance of the keywords and description to avoid affecting SEO due to excessive concatenation.

Q3: If I want to put the brand name at the beginning of the title,addCan the filter still be implemented?

Absolutely. Just adjustaddThe order of the filter concatenation is sufficient. For example, if you want to display 'Your Brand Name - Page Title', you can write it like this:<title>{% system with name="SiteName" %}|add:" - " |add:{% tdk with name="Title" %}</title>Here, we first get the brand name, then add a separator, and finally concatenate the actual page title to achieve the effect of the brand name in front.