In website operation, we often encounter situations where we need to quickly adjust certain information, such as updating the link of the help page, changing the status of a feature switch, or displaying some custom text that does not change often but needs to be flexible to modify.If each modification requires delving into the code file, it will undoubtedly greatly reduce efficiency.

AnQiCMS (AnQiCMS) understands this pain point and therefore provides a very convenient custom setting mechanism, allowing you to easily configure any content in the background without writing code, and present it in the website template.

Backstage settings: Configure your custom content

To implement this feature, first we need to make simple configuration in the Anqi CMS backend.This usually involves the 'Global Function Settings' section in the 'Background Settings'.Here, you can find a section named 'Custom Settings Parameters'.

Suppose we want to display a link to our help page in the website footer, and this link may be updated from time to time. We can add a custom parameter here:

  • Parameter Name (Parameter Name):HelpUrl(Suggest using camelCase naming, pure English letters, which will be more standardized and convenient when calling in templates)
  • Parameter Value:https://www.yourdomain.com/help(Enter your actual help page URL)
  • Remark (Remark):网站帮助页面的链接(Used to describe the purpose of the parameter, for your and other operators to understand)

The parameter name is the unique identifier you use when calling the template, and it is recommended to use clear, meaningful letters.The parameter value is the specific content you want to display. The remark field is used for internal management, helping you and other operators to understand the purpose of the parameter.

Template call: display custom content on the website

After the custom parameter is configured in the background, the next step is to introduce it into the website's front-end template. Anqi CMS provides powerful template tag functions, especiallysystemLabel, it is the core to obtain the global configuration information of the website.

systemThe tag is mainly used to obtain various parameters configured in the "Global Function Settings" of the background, including the website name, website logo, filing number, and of course, the parameters we customize.

To call the setting we just madeHelpUrlYou can use it in the template file (for examplefooter.htmlorheader.html) in the following way:

<a href="{% system with name="HelpUrl" %}" target="_blank">帮助中心</a>

This code will directly output the valueHelpUrlset in the background and use it as a hyperlink<a>label'shrefProperty.

If you wish to store this value in a variable first, in order to use it multiple times in the template or for other logical judgments, you can do it like this:

{% system helpPageUrl with name="HelpUrl" %}
<a href="{{ helpPageUrl }}" target="_blank">帮助中心</a>
<p>更多信息请访问:{{ helpPageUrl }}</p>

Here, we first declareHelpUrlthe value was assigned tohelpPageUrlThis variable can be freely referenced in the template. This method improves the readability and maintainability of the code and avoids repeated calls to the label.

Beyond Link: More Custom Content Usage

The power of custom parameter settings goes far beyond this. In addition to simple URLs, you can also store other types of content such as:

  • Website announcement text:Configure a short announcement in the background, such as 'Notice of suspension of shipment during the National Day holiday', which is displayed at the top navigation through tags.
  • Website statistics code snippet:For some common, non-sensitive third-party integration codes (such as website statistics IDs), they can be flexibly managed through custom parameters, making it convenient to replace.
  • Feature switch:Configure a boolean value (such asIsNewFeatureEnabledwith a value oftrueorfalse),pass through the template({% if %}Tag to determine whether to display a new feature module or an advertisement
  • Phone numbers or addresses for different regions:If your website serves multiple regions, you can set up different contact methods for each region using custom parameters and display them in the template through logical judgment.

CombinecontactLabel (specifically for contact information) anddiyThe label (used for more general custom content), Anqi CMS provides you with great content operation flexibility, allowing you to easily meet various content display needs.

Tips and注意事项

  • Naming conventions:Choose clear and consistent English names for custom parameters, which are convenient for future management and search. Avoid using overly generic names or those that may conflict with system-built-in parameters.
  • Use moderately:Avoid storing large, frequently changing, or complexly structured data as custom parameters; these are better managed through content models or data lists to maintain data structure and maintainability.
  • Test verification:After each modification of the custom parameters, be sure to clear the website cache and visit the front page to confirm that the content is displayed correctly. If the content contains HTML code, it may be necessary to use|safeThe filter ensures that it is parsed correctly rather than escaped.

By using the custom settings and template tags provided by AnQi CMS, you can easily display any content configured in the backend on the website front end, greatly enhancing the efficiency and flexibility of website operation.Whether it is a simple URL update or a complex text display, it can be completed without touching the code, making content management more convenient.


Frequently Asked Questions (FAQ)

  1. Can I enter HTML code directly in the custom parameters? If so, how can I ensure it is displayed correctly on the front end?Can. You can enter HTML code in the 'Parameter Value' of custom parameters.To ensure that these HTML codes are correctly parsed by the browser on the front-end page instead of being displayed as plain text, you need to use it when calling the template|safea filter. For example:<div>{% system myHtmlContent with name="MyHtmlContent" %}{{ myHtmlContent|safe }}</div>Please note that using|safeMeans you trust the safety of this HTML content, avoiding XSS risks.

  2. I set custom parameters and referred to them in the template, but why is the front-end page not displaying or displaying incorrectly?First, please check if the custom parameter's "parameter name" matches the one in the templatenameThe value is completely consistent (including case). Secondly, after modifying the background settings, you may need to clear the website cache for the changes to take effect.You can try to clean up in the "Update Cache" feature of the background management interface.If the problem still exists, please check if your template file has been saved and uploaded correctly.

  3. What is the difference between custom parameters and content models (such as article, product models)? How should I choose?Custom parameters are more suitable for storing small, global, or cross-page reusable, and relatively simple single-value content, such as help page URLs, some text in the company profile, website announcements, and so on.They usually do not have complex structures and a large number of fields. The content model is used to manage a large amount of structured, multi-field content, such as articles, products, use cases, etc., which usually have complex attributes such as categories, tags, images, detailed content, and require functions such as list display, detail page display, and search.In simple terms, custom parameters are 'small and clever' global configurations, while the content model is 'large and comprehensive' data management.