Does the `{% diy %}` tag support retrieving custom content created by the rich text editor and rendering it?

Calendar 👁️ 58

As an experienced website operation expert, I am also a deep user of AnQi CMS, I am glad to have an in-depth discussion with everyone{% diy %}The ability of the tag in handling rich text content rendering.In the flexible and powerful template system of AnQi CMS, understanding the characteristics of each tag is crucial for achieving accurate and efficient content display.


Of Security CMS{% diy %}Label: Does custom content support deep parsing of rich text rendering?

The Anqi CMS, with its simple and efficient features and highly customizable characteristics, has become a powerful assistant for many small and medium-sized enterprises and content operation teams.In the operation of daily websites, we often need to add some customized, global content, such as copyright information in the footer, contact information in the sidebar, or some special marketing slogans.{% diy %}The label has become our preferred tool.But a common question that arises is: Can this tag directly support content created from a rich text editor and render it as the article details do?

{% diy %}The core positioning and function of the label

First, let's review{% diy %}The core positioning of tags in AnQi CMS. Based on our in-depth understanding of AnQi CMS template tags,{% diy %}The primary function of the label (i.e., "custom content label") is to obtain various custom parameters configured in the "custom settings" module of the background. It is a powerful "universal getter" that can retrieve values based on the custom fields you set up in the background.nameParameters, extract the corresponding values. These values are usually text information such as website names, phone numbers, social media links, etc., which are relatively flat and have a simple structure.

For example, if you add a parameter namedAuthorwith the value of “AnQi CMS Operation Team”, you can easily pass through it in the template{% diy with name="Author" %}To fetch and display this text. Its basic usage, whether it is to fetch simple text or URL, always follows the direct string retrieval logic.

The conventional way to handle rich text content in AnQi CMS

However, rich text content, such as the main text of articles entered through the background rich text editor, product descriptions, etc., includes HTML structure and may even be in Markdown format.AnQi CMS has a special rendering mechanism for these core content fields.

For example, when you go through the document detail page,{% archiveDetail with name="Content" %}When retrieving the article content, if the Markdown editor is enabled on the backend, the system will automatically convert Markdown to HTML. In addition, it also supportsrenderParameter, allows you to manually control whether to perform Markdown to HTML conversion(render=true|false), as well aslazy="data-src"Such properties are used to handle advanced functions like lazy loading of images. Moreover, to avoid the browser displaying any output that may contain HTML code as plain text, we usually need to use it in conjunction with|safeA filter that tells the template engine that this content is safe HTML and can be directly parsed by the browser.

{% diy %}The truth about tags and rich text content

Now, let's go back to{% diy %}Label. By consulting the documentation and actual operating experience, we can clearly draw a conclusion: {% diy %}The tag itself does not have the built-in feature of automatically rendering rich text editor content, it does not automatically convert Markdown to HTML, nor does itrenderThis parameter is provided for direct use.

{% diy %}The original intention of the tag is to obtain the original string value stored in the background custom settings. This means that when you use{% diy %}When a label retrieves the value of a custom field from the backend, it will output any content you enter in the backend unchanged.

If your custom field accidentally contains HTML or Markdown formatted text, then use it directly in the template{% diy %}You will see the raw code uninterpreted, not the expected rendering effect.

To solve this problem, we need to intervene manually:

  1. For custom content that includes HTML code:You need to handle it in the template as you would with core content fields:{% diy %}Apply the output of the tags to|safeFilter. This will inform the template engine that the output string is safe HTML that can be parsed by the browser.

    {# 假设后台某个名为"FooterRichText"的diy字段中存储了HTML内容 #}
    <div>
        {% diy footerInfo with name="FooterRichText" %}
        {{ footerInfo|safe }}
    </div>
    
  2. For custom content that includes Markdown formatting:due to{% diy %}It does not automatically convert Markdown, you need to apply it first|renderThe filter converts it to HTML first, then use|safeThe filter ensures that HTML is rendered correctly.

    {# 假设后台某个名为"AboutUsContent"的diy字段中存储了Markdown内容 #}
    <div>
        {% diy aboutUsMarkdown with name="AboutUsContent" %}
        {{ aboutUsMarkdown|render|safe }}
    </div>
    

    Please noteHere is the|renderThe filter is a general-purpose content rendering filter (such asfilter-render.mdThe aforementioned can be applied to any string variable that may contain Markdown, not limited to core content fields.

Operation suggestions and **practice**

Based on the above analysis, as a website operator, we should choose an appropriate management method according to the nature of the content:

  • Simple, non-formatted text or links:Use the background custom settings preference{% diy %}Tags. This is more lightweight and convenient to manage.
  • Need structured and formatted rich text content (such as articles, product introductions, independent 'About Us' pages, etc.):It is strongly recommended to create and edit through a content model (article, product) or single-page management.These modules are built-in with rich text editors and provide comprehensive Markdown conversion and HTML parsing support during template rendering.

By properly distinguishing and using the various functions of the Anqi CMS, you will be able to manage website content more efficiently and ensure the correct rendering and user experience.


Frequently Asked Questions (FAQ)

  1. Q:{% diy %}What types of custom content can the tag retrieve?A:{% diy %}Tags are mainly used to obtain unstructured or semi-structured data configured in the "Custom Settings" of the background, such as plain text, numbers, brief descriptions, URLs, switch states, and so on.It is usually in a simple key-value pair form.

  2. Q: Why do I use{% diy %}The HTML content output by the tag is displayed as raw code on the page instead of the rendered effect?A:{% diy %}The tag defaults to outputting the original string and does not automatically parse HTML. If you enter HTML code in a custom field, you need to add the output result in the template.|safeFilter, for example{{ diyField|safe }}This way the browser can identify and render it as HTML.

  3. **Q: If I want to in{% diy %}

Related articles

How to ensure that the custom content obtained by the `{% diy %}` tag is safely output in the front-end template?

As an experienced website operations expert, I know that the flexibility of the Content Management System (CMS) is both an advantage and may bring potential security challenges.AnQiCMS is widely popular among many enterprises and content operators for its simplicity, efficiency, and powerful customizability.One of its core functions is to obtain custom content from the background through the `{% diy %}` tag, which greatly enriches the dynamism of the template.However, how to ensure that these custom contents are safely output in the front-end template and avoid potential risks is a problem that every operator must seriously consider.

2025-11-06

Does using the `{% diy %}` tag affect page loading speed or SEO?

In the daily operation of Anqi CMS, we often encounter questions about how template tags affect website performance and SEO effects.Today, let's delve into the usage of the `{% diy %}` tag and see if it really becomes a bottleneck for page loading speed or has a negative impact on search engine optimization.As an experienced website operation expert, I deeply understand that AnQiCMS, developed with high-performance architecture in Go language and rich SEO optimization tools as its core advantage, aims to provide an efficient and customizable content management solution. Therefore

2025-11-06

How to implement dynamic loading of image URL and custom media resources with `{% diy %}` tag?

As an experienced website operation expert, I am well aware that the flexibility and customization of website content are crucial for maintaining competitiveness in the ever-changing online environment.AnQiCMS (AnQiCMS) with its efficient architecture based on the Go language and powerful features, provides us with a flexible content management platform.

2025-11-06

Can the custom parameter value obtained from the `{% diy %}` tag be directly used in conditional judgments within the template?

As an experienced website operations expert, I am well aware of the convenience and strength that AnQiCMS (AnQi CMS) brings to us in content management and website operations.Its flexible template engine and rich tag features make it possible to build and maintain websites efficiently.Today, let's delve deeply into a common problem encountered in template development: 'Can the custom parameter value obtained from the `{% diy %}` tag be used directly for conditional judgments in the template??

2025-11-06

What are the functional differences between AnQiCMS' 'custom content tags' and traditional CMS 'custom fields'?

As an experienced website operations expert, I am well aware that the core of a content management system (CMS) lies in its ability to organize and present content.AnQiCMS is an enterprise-level content management system developed in Go language, with unique flexibility in content models.Today, let's delve into the functional differences between the 'Custom Content Tags' in AnQiCMS and the 'Custom Fields' of traditional CMS or AnQiCMS itself, hoping to help everyone understand more clearly how to use these tools to optimize content operation strategies.--- ###

2025-11-06

How to create and manage custom parameters for the `{% diy %}` tag in AnQiCMS backend?

Anqi CMS, as an enterprise-level content management system known for its efficiency and customization, its powerful template tag feature is undoubtedly a helpful tool for content operators and website developers.In daily website operations, we often encounter the need to quickly adjust some global and site-level configuration information, such as the company's slogan, a link to a specific event, or a temporary announcement text, etc. These pieces of information do not require complex classification and models like article content, but are more flexible than hard-coded in templates.This is provided by Anqicms with `{% diy

2025-11-06

How to use the `{% diy %}` tag to get custom parameters and control formatting and styling on the front end?

As an experienced website operations expert, I am well aware that the flexibility of a Content Management System (CMS) is the key to improving operational efficiency and website performance.AnQiCMS (AnQiCMS) stands out in this aspect due to its excellent customizability, especially with the feature of obtaining custom parameters through the `{% diy %}` tag, which brings great convenience and imagination space for the layout and style control of front-end content.Today, let's delve into how to巧妙运用 this feature, making your website content both beautiful and functional.

2025-11-06

Can the `{% diy %}` tag be used to call custom configurations of specific modules, such as only for the article module?

In the practice of template development for Anqi CMS, the `{% diy %}` tag is used frequently, providing website operators with great flexibility to customize and call various information configured in the background.However, many developers may feel confused about whether it can accurately call a custom configuration for a specific content model such as "only for article modules".Today, as an experienced website operations expert, I will deeply analyze this mechanism based on the AnQi CMS documentation and guide you on how to correctly use template tags in different scenarios.

2025-11-06