How to customize system parameters in AnQiCMS backend to meet the special calling requirements of the frontend template?
Unlock the potential of the front-end template: The Art of AnQiCMS Backend Custom System Parameters
In website operation, we often encounter such situations: front-end templates need to display some non-standard but crucial information for the business, such as a special marketing campaign link, WhatsApp contact information other than WeChat and phone, or a disclaimer at the bottom of a specific page.If each modification touches the code, it will undoubtedly greatly reduce the operational efficiency.AnQiCMS as an enterprise-level content management system, deeply understands this, and provides us with flexible and powerful custom system parameter functions, allowing us to easily manage these 'special requirements' in the background, and seamlessly call them in the front-end template, thus realizing the refined operation of content and display.
This article will delve into how to customize system parameters in the AnQiCMS backend, and guide you on how to elegantly call these parameters in the frontend template, ensuring that your website can maintain efficient content updates while meeting various unique display needs.
Understand the requirements: Why do we need to customize system parameters?
The website operation is a dynamic process, the content display requirements often change.AnQiCMS is built with rich preset fields, which are enough to deal with most common content, such as website name, copyright information, contact phone number, etc.But there are always some personalized needs that cannot be met by general fields. For example:
- Multi-channel contact information:In addition to the default phone, email, and WeChat, you may also need to display WhatsApp, Telegram, or Facebook Messenger links.
- Temporary promotional activity:A prominent banner is needed on the homepage or a specific area, linking to the latest promotional page, and the link needs to be updated frequently.
- Specific page statement:A product category page needs to display industry-specific legal statements or risk warnings.
- Third-party service integration:Embed a dynamically adjustable third-party statistics code ID or API Key.
Faced with these scattered but important requirements, if you modify the template file each time, it is not only inefficient but also easy to introduce errors.The AnQiCMS custom system parameter feature was born to solve these pain points, it frees these 'variables' from the code, and entrusts them to be managed centrally by operations personnel in the background.
AnQiCMS Backend: Entry for parameter customization.
In the AnQiCMS backend, the customization of system parameter settings is mainly concentrated in several sub-menus under the "Backend Settings" area. These two areas are the starting points for parameter expansion:
Global feature settings(
help-setting-system.mdReference):This area mainly manages the basic information of the website, such as the website name, Logo, filing number, website address, etc.It also provides a "Custom Setting Parameters" section that allows you to add any parameters related to the website's global configuration that are not in the default list.For example, you can define a "Help Page URL (HelpUrl)" or "Website Theme Color (ThemeColor)" and so on here.Contact information settings(
help-setting-contact.mdReference):As the name implies, this is the place to manage all external contact methods, such as contacts, phone numbers, addresses, email addresses, and WeChat IDs, etc.Similarly, this module also has the function of "custom setting parameters", which is very suitable for adding additional social media links or specific business contact information, such as the WhatsApp account mentioned earlier.
Through these two entries, you can abstract the content that may have been hard-coded in the template into parameters that can be flexibly configured in the background.
Precise customization: Creating and managing custom parameters
Let us take the example of adding a custom parameter named 'Help Page Link' in the 'Global Feature Settings' to demonstrate the creation process.
- Navigate to the settings page:Log in to the AnQiCMS backend, click the left menu's 'Backend Settings', then select 'Global Function Settings'.
- Add custom parameters:Scroll to the bottom of the page, find the "Custom Settings Parameters" area. Click the "Add Custom Parameter" button.
- Enter parameter information:
- Parameter name:This is the most important field, it will serve as the identifier for calling this parameter in the front-end template. It is recommended to use camelCase naming convention for the sake of code tidiness and readability, for example
HelpUrlAvoid using Chinese or special characters, as this may cause template parsing errors. - Parameter value:Fill in the actual content of the parameter, for example
https://en.anqicms.com/helpThis value can be plain text, a URL, or even a short HTML snippet (if needed, the front-end should pay attention to safe escaping when calling). - Note:This is an optional but strongly recommended field. Here, clearly describe the purpose of this parameter, such as 'link to the user help and support page', which will greatly help other operators or future you to understand the meaning of this parameter.
- Parameter name:This is the most important field, it will serve as the identifier for calling this parameter in the front-end template. It is recommended to use camelCase naming convention for the sake of code tidiness and readability, for example
- Save:After filling in, click the save button. At this point, a new custom parameter has been successfully added and is now effective.
The same steps also apply to the custom parameters in the "Contact Information Settings". For example, you can add a "Parameter Name" ofWhatsAppwith a value of+861234567890The parameter marked as 'Customer WhatsApp contact number'.
How to elegantly call custom parameters in the front-end template?
AnQiCMS's template engine adopts a syntax style similar to Django, making it intuitive and efficient to call back-end parameters on the front end. The core lies in the use of specific tags ({% tag %}) and variable ({{ variable }}) to retrieve data. For the custom parameters we just created, we will mainly use{% system %}/{% contact %}and{% diy %}these tags.
Call the custom parameter in the global function setting:
{% system %}For custom parameters created in the "Global Feature Settings", you can use{% system %}tags to call. For example, to get the one we defined earlier,HelpUrl:<a href="{% system with name="HelpUrl" %}" target="_blank">帮助中心</a>If you want to store the value you get into a variable for subsequent processing, you can do it like this:
{% system helpPageUrl with name="HelpUrl" %} <a href="{{ helpPageUrl }}" target="_blank">访问我们的帮助页面</a>This way, even if the link of the help page changes in the future, you only need to modify the parameter value in the AnQiCMS background without touching any code.
Call the custom parameter in the contact information settings:
{% contact %}Similar