How to set and get custom website sidebar content using the `{% diy %}` tag?

Calendar 👁️ 72

As an experienced website operations expert, I am well aware that the flexibility of the website content management system is crucial for operational efficiency.AnQiCMS (AnQiCMS) provides us with many powerful content management features with its concise and efficient architecture.Today, let's delve into one of the very practical and flexible features - how to make use of{% diy %}Set and get custom website sidebar content.

Unlock the secret to custom CMS sidebar of AnqiCMS.{% diy %}Flexible use of tags

In website operation, the sidebar (Sidebar) often plays an important role.Whether it is to display the latest news, popular articles, ad slots, social media links, or important announcement information, a well-designed, easy-to-update sidebar can greatly enhance user experience and website conversion rates.However, if it is necessary to modify the template code every time the sidebar content is updated, it will undoubtedly bring a huge burden to the operation work.Aanqi CMS is well-versed in this, through its powerful{% diy %}Tags, provide us with an elegant solution, making sidebar content management simpler than ever before.

I. Understanding the need for custom sidebar

Imagine your website is running a marketing campaign and needs to add a prominent banner or countdown timer to the sidebar of all article pages.Or, would you like to adjust the list of recommended products according to the change of seasons, or even to optimize SEO by regularly updating some core keywords related text links.If this content is hard-coded in the template, any change requires the involvement of developers, which is not only time-consuming and labor-intensive, but may also pose potential risks due to unfamiliarity with the code.

We need a mechanism at this point that can easily adjust any content of the sidebar through the back-end management interface without modifying the template file.{% diy %}The tag is just for this. It allows us to define any number of custom content blocks in the Anqi CMS backend, and dynamically call and display these contents at any position on the website frontend, especially in the sidebar.

Part two: Unveiling{% diy %}Tags: Entry to custom content

{% diy %}Tags play the role of a 'universal content container' in Anqi CMS.The core function is to obtain the corresponding "parameter value" based on the preset "parameter name" from the "custom setting parameters" in the background.These parameter values can be plain text, HTML code snippets, or even image links.This design concept allows the various non-structured content areas of the website (such as the sidebar) to be separated from the core content publishing process, realizing independent and convenient management.

This means that once the backend is set up, operations personnel can update the website's sidebar, footer information, popup announcements, and any other small blocks of content that need to be dynamically displayed in multiple places on the page, without touching a single line of code.

Step 3: Practical Operation: Set Custom Sidebar Content

Now, let's practice step by step how to{% diy %}Tags to add vitality to our website sidebar.

1. Define your custom parameters in the background

Firstly, we need to create or modify the custom content used for the sidebar in the Anqicms background management system.

  1. Log in to the backend:Access your AnQi CMS backend management address (usually)your-domain/system/)
  2. Navigate to the settings area:In the left menu, find the "Background Settings" category. Anqi CMS provides multiple areas to define custom parameters, such as "Global Function Settings" or "Contact Information Settings".For such general sidebar content, we usually add it in the 'Global Function Settings'.Click to enter the "Global Settings".
  3. Add custom parameters:At the bottom of the "Global Function Settings" page, there is usually an area for "Custom Setting Parameters". Click the "Add Custom Setting Parameter" button (or a similar entry).
  4. Enter parameter information:
    • Parameter name:This is the most important identifier, equivalent to the unique ID of this custom content block, for front-end template calls. Please use a combination of letters, numbers, and underscores to ensure its uniqueness and descriptiveness, for exampleSidebarLatestNewsTitle(Sidebar latest news title),SidebarAdBannerHtml(Sidebar banner HTML).
    • Parameter value:Enter the content you want to display in the sidebar. This can be simple text, such as "Hot Recommendations", or complex HTML code snippets, such as an ad block with links and images:
      
      <a href="/promotion-page" target="_blank">
          <img src="https://en.anqicms.com/uploads/ad-banner.jpg" alt="最新促销活动" style="max-width: 100%;">
      </a>
      
    • Note:This is an optional field, used to explain the purpose of this parameter. Good remarks can help you or your team members quickly understand the use of each parameter during later maintenance.
  5. Save settings:After filling in, click the save button to ensure that your custom parameters have been successfully entered into the system.

2. In the template usage{% diy %}Label fetch content

Next, we need to modify or create your website template file so that it can call the custom content defined just now in the sidebar.

  1. Locate the template file:According to your template structure, the sidebar content is usually located in a separate template fragment file (such aspartial/aside.html), or directly embedded in the main layout file (such asbase.htmlIn the background. You can find these files to edit in the "Template Design" function.
  2. Insert{% diy %}Tags:Insert at the location where you want to display custom content.{% diy %}.
    • Directly output the content:If you want to print the parameter value directly, you can use it like this:
      
      <div class="sidebar-block">
          <h3>{% diy with name="SidebarLatestNewsTitle" %}</h3>
          <!-- 其他侧边栏内容,如文章列表 -->
      </div>
      
    • Assign the content to a variable and render it safely (recommended for handling HTML content):If your parameter value contains HTML code, to ensure that HTML is parsed correctly and not displayed as plain text, and to avoid potential security risks (XSS), we recommend assigning it to a variable and using|safeThe filter performs rendering.
      
      <div class="sidebar-block ad-area">
          {% diy adContent with name="SidebarAdBannerHtml" %}
          {% if adContent %} {# 判断参数值是否存在 #}
              {{ adContent|safe }} {# 使用 |safe 过滤器确保HTML代码被浏览器解析 #}
          {% else %}
              <p>暂无广告</p> {# 如果后台未设置内容,可以显示备用信息 #}
          {% endif %}
      </div>
      
      Please note,|safeThe filter is very important. It tells the Anqi CMS template engine that the content you provide is safe and can be rendered directly as HTML without escaping.
  3. Save template:After modification, save the template file and clear the website cache (usually there is a "update cache" function in the background), so that the changes take effect immediately.

Now,

Related articles

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

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

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

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

The value obtained by the `{% diy %}` tag, can it be further processed in the filter?

As an experienced website operation expert, I have accumulated rich experience in the practical application of AnQiCMS, and I particularly understand the importance of content flexibility to the vitality of a website.Today, let's delve into a question that many AnQiCMS users have been curious about: whether the custom value obtained from the `{% diy %}` tag can be further processed in template filters?In short, the answer is affirmative, and this ability greatly broadens the imagination space for AnQiCMS template customization and content operation.

2025-11-06

The `{% diy %}` tag supports multiple calls to different custom content on the same page?

The `{% diy %}` tag of AnQiCMS: a powerful tool for flexibly handling web page content As an experienced website operation expert, I fully understand the importance of a flexible and efficient content management system for a corporate website.AnQiCMS (AnQiCMS) with its excellent feature design provides us with many conveniences in the content operation field.

2025-11-06

What is the main function of the 'Document Tag' feature in AnQiCMS?

As an experienced website operations expert, I know that every function of the Content Management System (CMS) can become a key to improving website operations efficiency and effectiveness.In AnQiCMS, such a content management system that focuses on enterprise-level applications and SEO optimization, the 'Document Tag' feature is not just a simple content classification, it is more like a multi-functional Swiss Army knife, providing deep empowerment for content organization, user experience, and search engine optimization.In AnQiCMS, the main function of the 'Document Tag' feature can be deeply understood from the following core dimensions

2025-11-06

How to add Tag tags for articles and products in the AnQiCMS background?

As an experienced website operations expert, I am well aware of the importance of tags (Tag) in content management and search engine optimization.AnQiCMS as an efficient and flexible content management system, its built-in tag function provides great convenience for operators.Today, let's delve into how to easily and efficiently add Tag tags to your articles and products in the AnQiCMS backend, and transform them into a powerful tool to enhance the value of your website.

2025-11-06