In website content operation, the page's 'Title', 'Keywords', and 'Description', which we commonly refer to as TDK, play a vital role in search engine optimization (SEO).A well-structured and brand identifiable page title that not only helps search engines better understand the page content, but also attracts users' attention in search results.AnQiCMS (AnQiCMS) provides a flexible template engine, allowing us to finely control this key information.

This article will focus on how to巧妙ly use template filters in Anqi CMSaddTo dynamically add the brand name or a fixed suffix to the page title, thus ensuring the consistency of the brand image and improving the overall SEO effect.

Understand the TDK management mechanism of Anqi CMS

In AnQi CMS, TDK is usually managed through the SEO settings of the backend editing page.Whether it is article details, category list, or single page, we can set SEO titles, keywords, and descriptions for them separately when editing.While at the template level, AnQi CMS provides powerfultdkUse tags to call this information. For example, in<head>Area, we often use such code to display the page title:

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

This code will directly output the title set in the background of the current page.However, sometimes we hope that all page titles can 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 would be very cumbersome to make changes once the brand name needs to be updated.It is particularly important to dynamically add this information at this time.

addFilter: the magic tool for text concatenation

The template engine of AnQi CMS supports various filters, among whichaddThe filter is a powerful tool for string concatenation and numeric addition. Its basic syntax is very intuitive: {{ obj|add:obj2 }}. Whenobjandobj2When they are strings, they are concatenated; when they are numbers, they are added together. It is this ability to concatenate strings that allowsaddThe filter becomes an ideal choice for dynamically constructing page titles.

Dynamically add the brand name or a fixed suffix to the page title

Now, let's see how to utilizeaddThe filter dynamically adds a 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 filter parameter.

First, throughtdkLabel retrieves the main title of the current page. Then, it usesaddthe filter to concatenate it with our preset suffix.

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

The meaning of this code is to retrieve the main title of the current page.TitleThen add the string “ | Your brand name” at the end of this title.

Method two: Dynamically obtain 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 Function Settings". We can utilizesystemTag to get these global configurations.

Assuming we set the website name to 'AnQiCMS Content Management System' in the 'Global Function Settings' on the backend.

We can do it like this<title>Used in tagsaddFilter:

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

We used it twice hereaddThe filter. First, it concatenates the main title of the page with the delimiter “-”, and then it concatenates the result with the throughsystemThe "website name" obtained by the tag is concatenated. In this way, no matter what the main title of the page is, it will ultimately end with " - AnQiCMS Content Management System" as a suffix.

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

Method three: usetdkBuilt-in tagssiteNameAttribute (convenient but less flexible)

Actually, the AnQi CMS hastdka built-in tag for page titlessiteNameAttribute, which can directly implement the function of adding the website name as a suffix.

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

WhensiteName=truethen,tdkThe label automatically retrieves the "Global Function Settings" from the background and appends the website name as a suffix to the page title, using "-" as the default separator. 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 suggestions with **location

To ensure that the brand name or suffix can be applied to all pages, it is recommended to includeaddof the filter<title>The code is placed in the public header file of the template, for exampletemplate/你的模板目录/bash.htmlortemplate/你的模板目录/partial/header.htmlIn. These files are usuallyextendsorincludeto other page templates, so that they can be modified and applied to the entire site at once.

When performing this operation, please pay attention to the SEO effect.The brand name or suffix added dynamically should be short, clear, and avoid keyword stuffing to prevent affecting user experience and the page title judgment of search engines.At the same time, ensure that the combined title length is moderate so that it can be fully displayed in the search results.

Frequently Asked Questions (FAQ)

Q1:addDoes the filter only allow string concatenation, can it perform numerical operations?

Yes,addThe filter can be used for both string concatenation and adding numbers. WhenaddThe filter receives two numeric values and performs mathematical addition operations.When at least one value is a string type, it will try to convert all values to strings and concatenate them.In the scenario of dynamically adding brand names, it will concatenate the page title (string) with the brand name (string).

Q2: BesidesTitle, I can also use in the TDK'sKeywordsorDescriptionis usedaddDo you want to filter to add content dynamically?

Of course you can.addThe filter also applies toKeywordsandDescriptionfields. For example, you can add some general 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, and 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 obtain the brand name, then add a separator, and finally concatenate the actual title of the page, thus achieving the effect of brand name precedence.