Drive AnQi CMS: Flexible customization of system-level parameters and efficient invocation in front-end templates
As a senior website operation expert, I know the importance of a flexible and customizable content management system for the efficient operation of enterprises.AnQiCMS (AnQiCMS) stands out with its high-performance architecture based on the Go language and rich features, excelling in content publishing, multi-site management, and SEO optimization. Particularly, it provides great convenience in customizing and invoking system-level parameters, allowing operators to easily manage all aspects of the website.
Today, let's delve into how the Anqi CMS allows you to customize system-level parameters and flexibly call them in front-end templates, thus achieving more dynamic and personalized website content presentation.
一、Why do we need to customize system-level parameters?
In the daily operation of websites, we often encounter some information that needs to be displayed uniformly throughout the entire site, such as the company's customer service phone number, unified social media links, corporate vision, special announcements, or some configurations that need to be quickly adjusted during specific periods.If this information is all hard-coded in the template, once a modification is needed, it means that multiple template files need to be modified, which undoubtedly increases the maintenance cost and also raises the risk of errors.
The system-level parameter customization function of Anqi CMS is designed to address this pain point.It allows us to centrally manage these global data in the background, and call them on the front-end as needed through concise template tags, achieving the separation of content and presentation, which greatly enhances the flexibility and operational efficiency of the website.
二、Customize your exclusive parameters in the security CMS backend
The backend setting area of Anqi CMS is the core hub for managing these system-level parameters.We can easily add and manage custom parameters through the 'Global Settings' and 'Contact Information Settings' entries.
Custom parameters in global function settings
First, log in to your security CMS backend, navigate to the "Backend SettingsOn this page, you will see the website name, website logo, filing number, and other default system parameters.The page bottom usually has an area for "Custom Settings Parameters".
Click the "Add" button to create a new custom parameter. Here you need to fill in three key pieces of information:
- Parameter nameThis is the unique identifier you call this parameter in the frontend template. It is recommended to use English camel case naming, such as
CompanyMottoorHolidayNoticefor easy understanding and distinction. - parameter valueThis is the actual content carried by this parameter.It can be plain text, a URL link, or even a brief HTML code snippet (if needed to render HTML directly on the front end).
- [en] NoteAdd a clear description for this parameter to facilitate understanding by you and other team members, avoiding confusion.
For example, if your company has a core corporate vision that needs to be displayed on multiple pages, you can set it up like this:
- Parameter name:
CompanyVision - Parameter value:
以创新驱动,赋能数字营销新时代! - Note:
企业文化愿景,用于首页和关于我们页面
- Parameter nameThis is the unique identifier you call this parameter in the frontend template. It is recommended to use English camel case naming, such as
Custom parameters in contact information settings
Similarly, in the "Background SettingsHere is a default contact information provided, including contact person, phone number, address, and email.Similar to global settings, there is also a "Custom Settings Parameters" area at the bottom of the page.
If you need to add some custom information that does not belong to the default contact methods, such as the company's WhatsApp link or specific holiday customer service hours, you can add them here. For example:
- Parameter name:
WhatsAppLink - Parameter value:
https://wa.me/xxxxxxxxxxxx - Note:
公司WhatsApp联系链接
This classification management custom parameter method helps maintain the order and maintainability of the background configuration.
- Parameter name:
3. Flexibly call custom parameters in the front-end template.
AnQi CMS providessystemLabel is used to get the parameters for global function settings, as well ascontactThe label is used to obtain the parameters for contact information settings. Whether it is a built-in parameter of the system or a parameter you customize, it is called through these two labels.
The basic syntax for calling these parameters is:{% 标签名称 变量名 with name="参数名" %}.标签名称It can besystemorcontact,参数名is the 'parameter name' you defined in the background.
Call parameters from the global settings.
Using the one we defined earlier.
CompanyVisionFor example, in your frontend template (such as)index.htmlorbase.html)中,You can call it like this:<div class="company-slogan"> <p>{% system with name="CompanyVision" %}</p> </div>If you want to store the parameter value in a variable first for more complex logical judgments or repeated use, you can use
setTags:{% set companyVision = '' %} {% system companyVision with name="CompanyVision" %} {% if companyVision %} <div class="company-slogan"> <p>{{ companyVision }}</p> </div> {% else %} <div class="company-slogan-fallback"> <p>抱歉,公司愿景正在更新中...</p> </div> {% endif %}This code not only called the parameters, but also demonstrated how to use
iflogical judgment tags, which display alternative content when the parameter value is empty, enhancing the robustness of the website.Call contact method settings parameter
Similarly, for the parameters defined in the "Contact Method Settings"
WhatsAppLinkThe calling method is also very similar:{% set whatsappLink = '' %} {% contact whatsappLink with name="WhatsAppLink" %} {% if whatsappLink %} <a href="{{ whatsappLink }}" target="_blank" rel="nofollow">联系我们 (WhatsApp)</a> {% endif %}Here we have also added
target="_blank"andrel="nofollow"Properties, this is a good practice for SEO optimization of external links and user experience.Handle parameters containing HTML content
If your custom parameter value contains HTML code and you want the front-end to directly parse and render these HTML instead of displaying the raw code, you need to use
|safeFilter. For example, if you have an announcement with special formatting or links:Backend parameter settings:
- Parameter name:
ImportantNotice - Parameter value: `Please visit our href=“/faq”
- Parameter name: