How to use the `add` filter to dynamically add a brand name or fixed suffix to the `Title` of the page `TDK`?

Calendar 👁️ 63

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.

Related articles

When handling floating-point number addition with the `add` filter, should special attention be paid to its calculation accuracy?

When using AnQi CMS for website content management, template tags and filters are tools we often use, greatly enhancing the flexibility of content presentation.Among them, the `add` filter allows us to perform addition operations of numbers or strings in the template, which is very convenient in many scenarios.However, when it comes to adding floating-point numbers (which are decimal numbers), some users may wonder: Does the `add` filter need to pay special attention to its calculation accuracy when handling such calculations?

2025-11-07

How to concatenate the area code and phone number in the contact (`contact` tag) using the `add` filter?

It is crucial to clearly and effectively display contact information when operating your website.AnQiCMS (AnQiCMS) with its flexible template engine and powerful tag system, allows you to easily achieve various complex display needs.Today, let's talk about a common but somewhat tricky requirement: how to concatenate the area code and phone number in the contact information using the `add` filter to make your phone number clear at a glance.Why do you need to concatenate the area code and phone number?

2025-11-07

Can the `add` filter be used to concatenate the website name and footer copyright information obtained from the `system` tag?

In website operation, we often need to finely control the display of page content, especially those global information that needs to be repeatedly displayed throughout the website, such as the website name, footer copyright, and so on.AnQiCMS (AnQiCMS) provides powerful template tags and filters to help us flexibly handle these requirements.Today, let's talk about a very practical scenario: Can the `add` filter of AnQi CMS be used to concatenate the website name and footer copyright information obtained from the `system` tag?The answer is affirmative, and this method is both intuitive and efficient.

2025-11-07

How to use the `add` filter in a `for` loop to dynamically generate a unique `id` or `class` attribute for list items?

In AnQi CMS template development, we often need to handle the display of dynamic lists.Whether it is an article list, product display, or other content block, dynamically generating a unique `id` or `class` attribute for each item in the list is particularly important in order to achieve finer style control, JavaScript interaction, or to ensure the uniqueness of page elements.Today, let's talk about how to cleverly use the `add` filter in the `for` loop of AnQiCMS to achieve this goal.### Understanding the demand for dynamic attribute generation Imagine that

2025-11-07

The `add` filter performs mathematical calculations in the AnQiCMS template, what is the difference from the arithmetic operation tag in `tag-calc.md`?

During the template development process of AnQiCMS, we often encounter scenarios where numerical calculations or logical judgments are required.The system provides us with various processing methods, among which the `add` filter and the arithmetic operation capabilities introduced in `tag-calc.md` are two commonly used tools.Although they all involve numerical processing, they have significant differences in functional positioning, usage, and complexity.First, let's understand the `add` filter.As the name implies, the `add` filter is mainly used to perform **addition operations or string concatenation**

2025-11-07

How to use the `add` filter in a loop to implement alternating row colors or dynamically concatenate different CSS class names?

In modern web design, the visual presentation of list content has an important impact on user experience.Whether it is an article list, product display, or comment section, by giving list items different styles, such as alternating row colors or applying different class names based on specific conditions, it can significantly improve the readability and aesthetics of the page.AnQiCMS is a powerful template engine that provides flexible tools to meet these dynamic style requirements, where the `for` loop's `cycle` tag and `add` filter are our reliable assistants.###

2025-11-07

What is the final concatenation result when one operand of the `add` filter is a number and the other is a string that cannot be converted to a number?

AnQi CMS is an enterprise-level content management system developed based on the Go language, dedicated to providing users with efficient and customizable content management solutions.In daily content operation and template development, we often use various template tags and filters to process data, where the `add` filter is a very practical feature that can help us conveniently perform numerical addition or string concatenation.However, when operands of mixed types are involved, the logic of their behavior becomes particularly important.

2025-11-07

How to use the `add` filter to dynamically add 'Published on:' before the blog post's publish time?

When operating a blog, we often hope that the publication time of the articles can be presented in a more intuitive and brand style compliant manner.For example, adding 'Published on:' before the date can make it clear to the reader that this is a published article.AnQiCMS (AnQiCMS) with its flexible template engine makes such customization very simple.Today, let's discuss how to cleverly use the built-in `add` filter of AnQiCMS to dynamically add the phrase 'Published on:' before the publication time of blog posts.

2025-11-07