Anqi CMS template development: usingsystemIntelligent label to get the current site language configuration
As a senior website operations expert, I am well aware of the importance of multilingual support for corporate websites and content operations in today's global internet environment.AnQiCMS, this is an enterprise-level content management system based on the Go programming language, which fully considers this point from the beginning of the design, providing powerful multilingual support features to help users easily expand into the international market.But configuring the language only in the background is not enough. How to flexibly obtain and utilize these language configuration information in the front-end template is the key to bringing out its true value.systemLabel, and how to get the current site's language configuration information through it.
systemExploring the label: the Swiss Army knife for getting global configurations
In the AnQiCMS template system,systemThe tag plays a Swiss Army knife-like role, it is specifically used to obtain various global configuration information at the site level. From the website name, Logo, filing number, to copyright content, website URL, even template path, etc., all these basic settings throughout the website can be accessed throughsystemThe label can be easily accessed. Its purpose is to safely and efficiently pass the general information configured in the background to the front-end, for templates to render.
systemThe basic usage of tags is very concise and clear, usually we would use it in the form of{% system 变量名称 with name="字段名称" %}. Here is thenameThe property is core, it specifies the specific configuration item you want to obtain. For example, if you want to get the name of the website, you can write it like this:{% system with name="SiteName" %}If you need to assign the result to a variable for subsequent complex processing, you can specify a variable name, for example{% system siteName with name="SiteName" %}{{ siteName }}.
Accurate positioning:name="Language"power
When focusing on how to obtain the language configuration of the current site,systemlabel'snamethe attribute has a very intuitive and powerful option:Language.
That's right, you just need tosystemput in the tag.nameset the attribute to"Language",AnQiCMS will intelligently return the language code currently configured on the site. For example, if your site is configured as Simplified Chinese in the background, it may returnzh-cnIf configured to American English, it will returnen-usThese language codes follow international standards and have high recognition and practicality
Then, what is the value of this in practical application?
The most direct application scenario is to set the root tag of the HTML document<html>Dynamic settinglangProperties.This is a very important web standard practice, which not only helps search engines better understand the language of the page content, thus optimizing multilingual SEO effects, but also improves the compatibility of assistive tools such as screen readers, providing a better access experience for users with special needs.base.htmlOr set in the common header template:
<html lang="{% system with name='Language' %}">
<head>
<meta charset="UTF-8">
<title>我的安企CMS站点</title>
<!-- 其他头部内容 -->
</head>
<body>
<!-- 页面主体 -->
</body>
</html>
This line of simple code makes your website automatically adapt the correct language declaration according to the backend configuration.This not only simplifies template maintenance, but also enhances the professionalism and user-friendliness of the website without a trace.
Practical application and advanced thinking
Except for<html>Label settingslangAttributes, the language configuration information obtained is very useful in content operation and template development:
- Dynamically loading language-related resources:You can load different CSS styles, JavaScript scripts, and even display different language versions of images or videos based on the current language.For example, a logo or thematic image of a specific country.
- Conditional rendering of content:In some cases, you may need to display different text or functionality modules on the same page based on the language.
systemThe language code returned by the tag can be used asifthe basis for logical judgment.{% if system.Language == "zh-cn" %} <p>欢迎来到中文站!</p> {% else %} <p>Welcome to our English site!</p> {% endif %} - Pass to JavaScript for use:If your front-end interaction logic needs to know the current page language, you can embed the language code in the JavaScript variable:
<script> const currentLang = "{% system with name='Language' %}"; console.log("当前站点语言是:", currentLang); // 基于 currentLang 执行其他 JS 逻辑 </script> - The flexibility of multi-site management:AnQiCMS has a significant advantage in supporting multi-site management. If you need to retrieveanotherSite language configuration (for example, displaying language information of child sites in the navigation of a main site),
systemLabels also support asiteIdparameter. By specifyingsiteIdYou can call the cross-site configuration, which is particularly useful for complex group websites or multi-brand operations.
In summary,systemlabel'sname="Language"An option provides a simple and powerful way for AnQiCMS template developers to programmatically obtain the language configuration of the current site.This not only improves the flexibility and maintainability of the template, but also lays a solid foundation for the globalization promotion, SEO optimization, and user experience of the website.Master and make good use of this tag, and it will give your AnQiCMS website operations a powerful boost.
Frequently Asked Questions (FAQ)
Question one: Where is the site language configuration of AnQi CMS set in the background?
Answer:In the AnQi CMS backend management interface, you can“Background Settings”Under the menuGlobal function settingsThe page finds and configures the default language package for the site. Here, multiple languages such as Chinese, English, and others are usually provided, and the language you choose will be set as the default language for the current site, and it can besystemThe label is obtained on the front end.
Question 2: Can I display a language switch list on the front-end template, so that users can easily switch to different language sites?
Answer:Of course you can. AnQiCMS provides a speciallanguagesLabel.This tag can retrieve the list of all configured multilingual sites, including their language names, language codes, and link addresses, etc.<a href="{{item.Link}}" hreflang="{{item.Language}}">{{item.LanguageName}}</a>to achieve the site's multilingual switching function.
Question 3: How should I operate to get the language configuration of the current site in Go backend logic?
Answer: systemTags are mainly used for front-end template rendering.In the Go language backend, AnQiCMS usually retrieves the language information of the current site through its internal configuration service or request context.GetSiteConfigorGetCurrentLanguageA function or method for business logic to call.If you carry out secondary development, you can refer to the AnQiCMS backend development documentation or source code to understand how to access these configurations from the Go code level.