What is the use of the `-` symbol in AnQiCMS template language?

Calendar 👁️ 60

As an experienced website operations expert, I fully understand the importance of every CMS detail for website performance and content display. In AnQiCMS (AnQiCMS) template language, a seemingly insignificant symbol, such as-But it contains the powerful ability to optimize output and enhance user experience. Today, let's delve deeper into this important role played by the AnQiCMS template language.-symbols.

AnQiCMS template language contains-Symbol: Master the details, optimize the output quality

AnQi CMS is known for its efficiency and customizability, making it the preferred choice for many enterprises and content operation teams.When building a website, templates play a crucial role in converting backend data into a user-visible interface.The template language design of AnQiCMS draws on the syntax of the Django template engine, allowing developers to flexibly control the presentation of content.In this flexible system,-The symbol plays a crucial role in certain specific scenarios - that isControl the output of whitespace.

Unnoticed challenge: unnecessary whitespace

During the template rendering process, in order to improve the readability and structuring of the code, we often use logical tags such as{% if %}/{% for %}/{% block %}Add line breaks and indentation before and after. However, when the template engine processes these tags, it sometimes outputs these whitespace characters used to beautify the template code to the final HTML as well.

Imagine when you define a loop in a template, iterating over a series of articles:

{% for item in archives %}
<li>
    <a href="{{item.Link}}">{{item.Title}}</a>
</li>
{% endfor %}

If no special handling is done, in the actual generated HTML,{% for %}and{% endfor %}The line containing the tag and its preceding and following newlines may be retained, thus causing unnecessary blank lines or whitespace in the HTML source code.Although this usually does not directly affect the visual effects of the page, it does increase the size of the HTML file and may make the source code look less tidy, causing inconvenience to subsequent debugging or SEO optimization.

As mentioned in the AnQiCMS document, this requirement is often used, such as in if-elseif statements or for loops, it will even output the blank lines of the if-else label part.-Punctuation to solve the pain point.

Refined and carefully crafted:-The art of blank control of symbols

In AnQiCMS template language,-When combined with logical tags, symbols become powerful tools for controlling whitespace. It mainly has two uses:

  1. Remove the whitespace before the tag:{%-When you are at the start of the tag{%Followed by a-That is written as{%-At that time, the template engine will intelligently remove all unnecessary whitespace characters before the tag, including line breaks.

  2. Whitespace characters after removing the tag:-%}Similarly, when you have a closing tag}immediately preceding-That is written as-%}the template engine will remove all unnecessary whitespace characters following the tag.

By combining these two forms, you can accurately control the whitespace around template logic tags, making the generated HTML code more compact and tidy.

For example, if we want the HTML generated by the above loop to have no extra blank lines, we can modify the template code like this:

{%- for item in archives -%}
<li>
    <a href="{{item.Link}}">{{item.Title}}</a>
</li>
{%- endfor -%}

After such processing,{%- for ... -%}and{%- endfor -%}The line occupied by the tag itself and its preceding and following newline characters will be removed, resulting in a more concise HTML output.This is very valuable for generating JSON, XML, or other whitespace-sensitive text formats, or simply for pursuing the highest quality of HTML code.

It's not just whitespace:-The other side of the symbol

Although blank control is-The symbol is used as a control character in AnQiCMS template languagecontrol characterThe core function, but the symbol itself also has other common uses in programming and text processing, and these may also appear in AnQiCMS templates:

  • Arithmetic operators:In mathematical expressions,-symbols can be used as a negative sign (such as{{ -10 }}) or a minus sign (such as{{ 10 - 5 }}). AnQiCMS'stag-calc.mddocument also clearly lists examples of its arithmetic operations.
  • Literal string: -It can also appear as a regular character in a literal string, as part of the data, for example, when settingtdklabel'ssepThe default value is-.
  • Part of the filter name:In some filters,-is also part of the name, such astruncatechars-htmletc. But this is not a control character, it is part of the filter function name.

However, these usages differ fundamentally from those in template language ascontrol characterof-there is a fundamental distinction. Only those placed after or{%before the template logic tags}are special symbols used for controlling whitespace.-are special symbols used for controlling whitespace.

Why is it so important? Value in operation practice

For website operators and optimization personnel, understanding and making good use of-The blank control function of symbols can bring various benefits:

  1. Cleaner HTML source code:Tidy HTML code is easier for developers to read and maintain, and reduces visual confusion caused by unnecessary whitespace.
  2. Slightly improve page loading speed:Remove extra whitespace can slightly reduce the size of the HTML file.Even though the reduction in the amount of a single file may not be significant, the cumulative effect can have a positive impact on page loading speed during high-traffic website or mobile access, which is crucial for SEO.
  3. Avoid potential rendering issues:Although not common, extra whitespace characters can cause unexpected layout shifts or script errors in some strict layout or CSS/JS processing scenarios.
  4. It is beneficial to generate non-HTML format files:If the AnQiCMS template is used to generate XML, JSON, or other text files that require strict formatting, precise control over whitespace is an essential ability.

In summary, the AnQiCMS template language includes-Symbols may not be eye-catching, but they are an essential, exquisite design that is indispensable for building efficient and tidy websites.Master its usage, and you will be able to better control the template output, providing users with a better access experience.


Frequently Asked Questions (FAQ)

  1. {%-and{{-What is the difference? {%-is used to controlLogical label(such asif/for/blockCharacters around the blank. It removes the extra line breaks or spaces that the logical tag itself may produce during rendering. And{{-is used to controlVariable outputThe surrounding whitespace characters. It removes any whitespace characters that may exist at both ends of the variable value, making the output more compact.The AnQiCMS document mainly mentions the blank control of logical tags, but understanding the difference between them is helpful for a more comprehensive application.

  2. overuse-What are the side effects of the symbol?overuse-Symbols, especially in scenarios where strict control of whitespace is not required, may make template code harder to read and understand. In most cases, browsers ignore multiple consecutive whitespace characters and blank lines in HTML, so not all places need to use-Suggest using it only when you need to eliminate extra spaces generated by logical tags, or when generating format-sensitive text (such as JSON/XML).

  3. except-In addition, does AnQiCMS template have other optimization output techniques?Of course. AnQiCMS provides a variety of optimization strategies for output, such as:

    • Filters (Filters):Utilizetag-filters.mdFilters described in detail process variables, such astruncatechars(truncated characters),striptags(remove HTML tags) etc., which can effectively clean and format content.
    • Static caching and SEO optimization:The built-in static cache mechanism and comprehensive SEO tools (such as TDK configuration, pseudo-static rules) of AnQiCMS are the key to improving website performance and search engine friendliness.
    • Image optimization:Inhelp-setting-content.mdThe WebP image format conversion, automatic compression of large images, and other functions mentioned, can significantly

Related articles

Why does the bottom of my AnQiCMS page always have extra blank lines?

Why does the bottom of the AnQiCMS page always have extra blank lines?Senior operations expert reveals the efficient solution method As a senior website operator, I know that some seemingly trivial problems in website construction and daily maintenance may confuse beginners as well as experienced developers.One common but annoying phenomenon is that some extra blank lines always appear at the bottom of the page.This not only affects the overall aesthetic of the page, but sometimes even ruins the layout, giving users an unprofessional feeling.Today, let's delve into it in depth

2025-11-07

How to completely eliminate blank lines generated by logical tags in AnQiCMS templates?

## AnQiCMS template development: completely eliminate the trouble caused by blank lines brought by logical tags In website frontend development, aesthetics and performance are often the two major goals pursued by developers.A clean and minimalist HTML output not only helps to improve page loading speed, but also avoids unexpected visual problems in certain specific layouts.

2025-11-07

What scenarios are suitable for the site-wide content replacement function

As an experienced website operations expert, I am well aware that efficient and flexible content management is the foundation of a successful website in an increasingly complex content ecosystem.AnQiCMS is an enterprise-level content management system developed based on the Go language, which brings significant value to many small and medium-sized enterprises and content operation teams with its lightweight and efficient features.Among its many powerful features, the 'Full Site Content Replacement' function is not often mentioned, but it can become a 'secret weapon' to solve operational pain points and greatly improve work efficiency in specific scenarios.Then, this seemingly simple "full-site content replacement" function

2025-11-07

What advanced SEO tools are built into AnQiCMS to improve website ranking?

As an experienced website operations expert, I know that in today's highly competitive online environment, whether a website can stand out largely depends on the performance of its search engine optimization (SEO).AnQiCMS (AnQiCMS) deeply understands this, it is not only an efficient content management system, but also seamlessly integrates a series of powerful advanced SEO tools into its core functions, aiming to help users improve the visibility and ranking of their websites in search engines from content creation to technical implementation level.Next, we will delve into these advanced SEO tools built into AnQiCMS

2025-11-07

What problem can be solved by using `-` in the `{% if %}` tag of AnQiCMS?

## Unlock the essence of AnQiCMS template: the `-` symbol in the `{% if %}` tag, say goodbye to annoying blank lines!During the template development process of AnQiCMS, whether it is an experienced developer or an operator who is new to templates, they may encounter a seemingly minor but occasionally annoying problem: extra blank lines or spaces generated by template tags when rendering.These 'hidden' characters, although they do not always affect the final presentation of the page, are required under certain precise layout requirements or when pursuing the ultimate simplicity of HTML structure

2025-11-07

How to avoid blank lines between list items when using AnQiCMS `for` loop?

As an experienced website operations expert, I am well aware that the neatness of the website front-end code has an indelible impact on page loading performance, SEO friendliness, and the developer's maintenance experience.When using an efficient content management system like AnQiCMS, we often need to dynamically generate content through template language, where the `for` loop is the core of building list pages.However, a common minor inconvenience is that sometimes unnecessary blank lines may appear between the list items output by the `for` loop, which makes the generated HTML code look a bit redundant

2025-11-07

What is the difference between `{%- tag %}` and `{% tag -%}` in AnQiCMS templates?

In AnQiCMS template development practice, every detail may affect the final presentation effect and code quality of the page.As an experienced website operations expert, I know that the standardization of template writing is not only related to the beauty of the page, but also closely related to the optimization of website performance and search engine friendliness.

2025-11-07

How to remove unexpected line breaks from the AnQiCMS template rendered HTML structure?

## Say goodbye to redundant spaces: AnQiCMS removal skills of extra line breaks in template rendering Hello everyone, friends of AnQiCMS!As an experienced website operations expert, I know that every detail is crucial on the road to pursuing website performance optimization and user experience.AnQiCMS with its efficient, secure, and SEO-friendly features, has become a powerful assistant for many small and medium-sized enterprises and content operation teams.In daily use, we often take advantage of its flexible template engine to build a variety of rich page layouts.

2025-11-07