How to determine whether a site has multilingual versions and display a language switch button using the `tag-languages` multilingual site tag?

Calendar 👁️ 55

AnQi CMS, as a Go language system deeply rooted in the field of enterprise-level content management, its powerful multilingual support is undoubtedly one of the core advantages that help enterprises expand into the global market.How can we intelligently judge whether the current site is configured with a multilingual version when we build websites for global users, and elegantly display the language switch button, which is a common problem that content operation experts may encounter in template design.Today, let us delve into the AnQi CMS together.tag-languagesLabel, uncover the mystery of language switching.

Anqi CMS language capability overview

In AnQi CMS's powerful feature matrix, multilingual support is one of its highlights.This is not only reflected in the system's built-in language packages that can switch the backend operation interface language, but more importantly, it provides a multi-site management solution at the content level, allowing you to provide completely independent and customized content experiences for users of different languages.This is different from simply translating the interface elements of a website, AnQi CMS is committed to achieving true multilingual 'site' management, allowing each language version to have its own domain name, content, and even SEO strategies.

Understanding this is crucial as it directly affects our grasp of the multi-language switching logic.In the system backend's 'Global Function Settings', although there is an option for 'Default Language Pack', it is more for the system's built-in prompts and backend interface language.And we discuss todaytag-languagesThe tag is used to retrieve the list of multi-language sites configured in the "Multi-site Management" section of the AnQi CMS backend, which is displayed to front-end visitors.

tag-languagesIn-depth analysis of tags

tag-languagesThe tag is a template tag designed by Anqi CMS specifically for handling multilingual site list.Its main function is to help you get all the multi-language site information configured in the front-end template.This information includes the language name, language code, site link, and other key data of the site, which provides a solid foundation for building a fully functional language switcher.

Core logic: Determine if the site has multilingual versions

Determine if the current site has multilingual versions and display the switch button,tag-languagesTags provide a very intuitive and elegant way. It does not require any parameters, just a simple call{% languages websites %}The system will return an array object containing information about all multilingual siteswebsites.

The key point is that if your Anqi CMS backendhas not configured any multilingual sitesthenwebsitesThis array will be empty. By using the conditional judgment ability of the template engine, we can easily realize the logic of dynamically displaying the language switch button. That is to say, only whenwebsitesThe language switch button will appear on the page when the array is not empty.

For example, the following code clearly shows how to make a judgment.

{%- languages websites %}
{%- if websites %}
    <div>
        <span>切换语言:</span>
        {# 遍历并显示每个语言站点 #}
        {%- for item in websites %}
            <a href="{{item.Link}}">
                {%- if item.LanguageIcon %}
                    <img src="{{item.LanguageIcon}}" alt="{{item.LanguageName}}"/>
                {%- else %}
                    {{item.LanguageEmoji}}
                {% endif %}
                {{item.LanguageName}}
            </a>
        {%- endfor %}
    </div>
{%- endif %}
{%- endLanguages %}

In this code block,{%- if websites %}This line is the core of determining whether a multi-language site is configured. IfwebsitesThis variable contains data from at least one language site, then the condition is true, the switch button'sdivThe language links inside the container will be rendered; otherwise, ifwebsitesis empty, then the entire multilingual switch part will not be displayed, ensuring the simplicity of the interface and the relevance of the function.

Tag parameters and available fields

tag-languagesThe tag itself is very concise,does not accept any parameters. It always tries to get the list of all configured multi-language sites under the current Anq CMS instance.

And when you go through{% languages websites %}Successfully obtainedwebsitesAfter the array, you can iterate over each oneitemrepresenting a language site, eachitemprovides rich field information for you to use, including:

  • LanguageName: Site language name in Chinese, for example 'Chinese', 'English'.
  • Language: Language's international standard code, for example 'zh-cn', 'en-us', which is for SEO'shreflangTags are especially important.
  • LanguageEmoji: An emoji representing a language, such as 🇨🇳, 🇬🇧, which can be used to make the interface more lively.
  • LanguageIcon: The icon URL for the language, you can upload a custom flag or language icon.
  • Name: Display name of the site.
  • Link: The complete URL of the language site, clicking on which will jump to the corresponding language version.
  • Remark: Site remark information.
  • Nofollow: Whether the link is added.nofollowAttribute (usually used for SEO).

Practice building multilingual toggle buttons

Based on the above fields, we can easily build a beautiful and practical multilingual switch button.For example, you can place this code in the header or footer of a website, even in a floating sidebar.Through combiningitem.LanguageIconoritem.LanguageEmojiYou can provide users with intuitive visual cues.

If you want the style to be more unified, you can preset a set of CSS rules for thedivandaLabel beautification, such as setting font size, color, hover effects, etc., so that the language switch button blends in with the overall design style.

SEO optimization considerations for multilingual websites

For a multilingual website, simply implementing content switching is not enough; it also needs to consider the SEO strategy. Anqi CMS supports multilingualism andtag-languagesTags provide convenience in this regard, especially throughhreflangthe use of tags.

hreflangThe tag tells search engines that your website has content in different languages or regions.This helps search engines provide the most relevant pages for users in different regions or languages, avoiding duplicate content issues and improving user experience.tag-languagesthe tags returned byitem.Linkanditem.Languagefield, which is to constructhreflangthe key data required for tags:

{# 将 Hreflang 标签放入 HTML 的 <head> 区块 #}
{%- languages websites %}
{%- for item in websites %}
<link rel="alternate" href="{{item.Link}}" hreflang="{{item.Language}}">
{%- endfor %}
{%- endLanguages %}

This code should be placed in the website template's<head>Within the area. It will generate one for each language site.link rel="alternate"The label clearly indicates the other language versions of the current page and their corresponding URLs and language codes, greatly enhancing the international SEO performance of the website.

Summary

Of Security CMStag-languagesThe label, with its concise and powerful features, provides a solid foundation for the construction and management of multilingual sites.By simple conditional judgments, we can not only intelligently display or hide the language switch button, but also flexibly use the site information provided, combine with SEO practices, and bring seamless and optimized browsing experience to global users.This is the embodiment of AnQi CMS as an enterprise-level content management system, committed to providing an efficient, customizable, and easy-to-expand solution.


Frequently Asked Questions (FAQ)

1.tag-languagesWhy does the tag return an empty list?

Iftag-languagesOr why is the tag not outputting any content in the template?websitesThe variable is empty, which is usually because you have not configured any multilingual sites in the "Multi-site Management" feature of the Anqin CMS backend.Make sure you have created and enabled at least one language site other than the default site.This tag will only return the list of multilingual sites that are actually configured and enabled in the background.

2. The default language package setting in the Anqi CMS backend andtag-languagesWhat are the differences between tags?

“Default language package” settings (located in the background “Global Function Settings”) mainly control the language used by the Anqi CMS background management interface and the system built-in prompts.For example, if you set it to 'English', the backend menu and prompts will become English. Andtag-languagesThe tag is used to get the front-end oriented, configured in the "Multi-site management".Content-level multilingual siteList. In short, the former affects the system UI, and the latter affects the content of the website and the language versions that visitors can switch between.

How to add style to a multilingual toggle button to make it look more beautiful?

tag-languagesThe tag itself is only responsible for outputting HTML structure and data, not any styles. You can use CSS to beautify the generated language switch button. For example, in the above code example, divWrapped text and various<a>tags. You can add class names todivoratags (')class) or directly through the selector, write CSS rules to control their layout, font, color, background, hover effects, etc., to keep them consistent with your website's overall design style.

Related articles

How to display the image gallery based on whether there is an album in the `Images` field of `archiveDetail` or `pageDetail`?

## How to cleverly use Anqi CMS: intelligently judge and display image galleries in articles/pages As a senior website operation expert, I deeply understand the importance of content display for user experience and website attractiveness.In AnQiCMS (AnQiCMS) such an efficient and customizable content management system, how to flexibly present image content, especially dynamically displaying the image gallery based on whether there is an album, is a focus for many operators.

2025-11-06

How to determine whether the current page is the homepage, category page, detail page, or single page, and load the corresponding SEO information?

As an experienced website operations expert, I am well aware of the importance of Search Engine Optimization (SEO) in the increasingly fierce online environment.To do SEO well, the primary task is to ensure that every page of the website provides clear and accurate metadata to search engines.How can one determine the current page type (home page, category page, detail page, single page, etc.) and load the corresponding SEO information, which is a core issue often encountered by many operators and developers.Today, let's delve into the intelligent design and practical strategies of AnQiCMS (AnQiCMS) in this aspect

2025-11-06

How to determine whether a user is logged in or has specific permissions to display private content in AnQiCMS templates?

As an experienced website operation expert, I fully understand the importance of realizing fine-grained content display in a content management system.Especially for systems like AnQiCMS that focus on enterprise-level applications and user experience, dynamically presenting content based on the user's login status or their permission group is a core strategy to enhance website personalization, achieve content monetization, and even build a membership system.Today, let's delve into how to skillfully utilize the powerful functions of the AnQiCMS template to achieve this goal

2025-11-06

How to use the `block` tag under the `if` condition to decide whether to override the parent template content when inheriting (`extends`) a template?

## Advanced Anqi CMS Template: Skillfully Using `extends` and `block` to Achieve Conditional Content Coverage We are well aware of the importance of website content maintainability and flexibility in the daily operation of website management for efficient operation.AnQi CMS provides a solid foundation for content management with its efficient architecture based on the Go language and a Django-like template engine syntax.Among them, template inheritance (`extends`) and content blocks (`block`) are the core of building reusable, easily expandable website layouts.But just inheriting and overriding is not enough, many times

2025-11-06

How to judge whether the `userDetail` user group is VIP and display exclusive identification in AnQiCMS templates?

In the daily operation of AnQiCMS, we often encounter the need to provide differentiated services and display content for different user groups.For VIP members, displaying a dedicated identifier not only enhances their sense of belonging but is also an important part of the website's content monetization strategy.As an experienced website operation expert, I know the importance of accurately identifying user identity and flexibly displaying content in templates.

2025-11-06

How to display different fields in `moduleDetail` based on model type (such as `article model` or `product model`)?

Deep analysis of AnQi CMS: How to display different fields in `moduleDetail` based on model type to create a personalized content experience As a senior website operation expert, I know that a truly excellent content management system is not just about publishing content, but also needs to be flexible to adapt to various content forms.AnQiCMS (AnQiCMS) performs exceptionally well in this aspect, its powerful 'content model' function is the secret weapon for us to achieve personalized content display.

2025-11-06

How to determine if the document list under a specified tag is empty?

AnQi CMS, as an enterprise-level content management system built with Go language, has always been committed to providing users with efficient, customizable, and secure content operation solutions.In our daily content management work, especially when building dynamic, intelligent websites, we often need to flexibly adjust the display of the page based on the presence or absence of content.Today, let's delve deeply into a very practical and elegant feature of Anqi CMS - how to use the `tag-tagDataList` tag to determine if the document list under a specified tag is empty.In AnQi CMS

2025-11-06

How to determine if the `Logo` field of `tagDetail` exists to display the cover image of the label?

As an experienced website operations expert, I know that how to flexibly and elegantly handle content display is the key to improving user experience and the professionalism of the website.Today, let's talk about how to cleverly judge whether the `Logo` field exists in the tag details of AnQiCMS (AnQiCMS), and decide whether to display the cover image of the tag.This is not just a technical implementation issue, but also about how we make the tabs more attractive.### Label cover image: The highlight of content operation In AnQi CMS

2025-11-06