Flexibly calling the system global configuration information in the website template is a key step in building a dynamic and easy-to-maintain website.AnQiCMS (AnQiCMS) is fully aware of this need and therefore provided powerful and intuitive template tags from the beginning, allowing users to easily display preset system-level data, contact information, and even customized information at any location on the page.
The AnQi CMS template system uses a syntax similar to the Django template engine, where variables are typically enclosed in double curly braces{{ 变量名 }}Define, and various operations and tags are represented by single curly braces and percentages{% 标签名 %}To implement. This design ensures that the template code is clear and easy to read. To call the global configuration information, we mainly usesystem/contactandtdkthese three core tags, as well as one for completely custom content.diy.
Invoke system-level basic configuration information(systemtags)
When we need to display the website name, Logo, filing number and other basic information in the page header, footer or any general area of the website,systemThe tag is our powerful assistant. This tag can obtain preset data from the background "global settings".
For example, to display the name of the website, we can write it like this in the template:
<title>{{ title }} - {% system with name="SiteName" %}</title>
This code will first retrieve the title of the current page, then append it to the website name set in the background. If you want to retrieve the logo image and display it, you can do it like this:
<a href="{% system with name="BaseUrl" %}">
<img src="{% system with name="SiteLogo" %}" alt="{% system with name="SiteName" %}" />
</a>
Here we not only display the Logo image, but also wrap it into a link pointing to the homepage address of the website. Similarly, the website's filing number (SiteIcp) and copyright information (SiteCopyright) Can be easily called:
<p>
<a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">{% system with name="SiteIcp" %}</a>
{% system with name="SiteCopyright" %}
</p>
Furthermore,systemThe tag can also get the basic URL of the website:BaseUrl) Mobile end URL:MobileUrl) Static file path of the current template:TemplateUrl) and site language (Language) and information for resource reference and multilingual adaptation. For example, when referencing template CSS files:
<link href="{% system with name="TemplateUrl" %}/css/style.css" rel="stylesheet">
It is worth mentioning that if you have enabled the multi-site management feature in the Anqi CMS backend and want to call data from other sites in the current template, you can do so bysiteIdSpecify the parameter, for example{% system with name="SiteName" siteId="2" %}.
Contact information of the website (contacttags)
Contact information of the website, such as phone number, address, email, social media links, etc., is often need to be managed uniformly and displayed on multiple pages.contactTags are born for this, it directly gets data from the "Contact Information Settings" in the background.
To display the contact phone number of the website, we can do it like this:
<div>联系电话:{% contact with name="Cellphone" %}</div>
Or contact email:
<div>邮箱:<a href="mailto:{% contact with name="Email" %}">{% contact with name="Email" %}</a></div>
If the background is configured with a WeChat QR code, the display is also very simple:
<div>
<img src="{% contact with name="Qrcode" %}" alt="微信二维码" />
</div>
contactTags not only support these built-in fields, but also allow users to customize parameters in the background "Contact Information Settings", such as adding a "WhatsApp contact". Once defined, it can be called like a built-in field:
<div>WhatsApp:{% contact with name="WhatsApp" %}</div>
Control the page's SEO meta information (tdktags)
SEO (Search Engine Optimization) is crucial for the visibility of a website. The page'stitle/keywordsanddescriptionis an indispensable part of it.}tdkTags are specifically used to obtain this meta information and support flexible display methods. This information also comes from the "Homepage TDK settings" or the SEO configuration of each content detail page.
In<head>Region, we usually use it like thistdkTags:
<title>{% tdk with name="Title" siteName=true sep="_" %}</title>
<meta name="keywords" content="{% tdk with name="Keywords" %}">
<meta name="description" content="{% tdk with name="Description" %}">
here,Titlelabel'ssiteName=trueIt will automatically add the website name to the end of the page title,sep="_"It defines the separator between the title and the website name.
For the canonical URL, this is an important SEO**practice to avoid duplicate content issues.tdkTags can also retrieve it, but we usually check if it exists first:
{%- tdk canonical with name="CanonicalUrl" %}
{%- if canonical %}
<link rel="canonical" href="{{canonical}}" />
{%- endif %}
This ensures that standard link tags are only output when necessary.
Flexible customization of global variables (diyTags and custom parameters
In addition to the above standardized configuration information, we may sometimes need to define some completely customizable global variables in the background, such as the link of a marketing campaign, some notification text, etc. Anqi CMS provides two ways to achieve this customization:
In
systemorcontactAdd custom parameters in the label:Just like wecontactthe tag withWhatsAppAdd custom parameters (for example, in the "Global Function Settings" or "Contact Information Settings"):HelpUrlThen go through the correspondingsystemorcontacttags toname="HelpUrl"Call in the form of.<div>帮助页面:{% system with name="HelpUrl" %}</div>Use
diyTags:diyTag is a more general custom content tag that directly corresponds to any globally defined field in the background.For example, in the background, we defined a field named
AuthorThe parameter, it can be obtained like this in the template:<div>网站作者:{% diy with name="Author" %}</div>
This flexible custom function allows us to expand and call various personalized global configurations according to the specific needs of the website.
By using these built-in template tags, Anqi CMS greatly simplifies the process of calling global configuration information.We just need to set the corresponding values in the background, and then use concise tag syntax in the template to achieve dynamic display and efficient management of website content.This not only improves the development efficiency, but also makes the website's post-maintenance and content updates more convenient.
Frequently Asked Questions (FAQ)
- **Ask: If I modify a global configuration in the background, but the front page