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

Calendar 👁️ 56

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 network environment.AnQiCMS (AnQiCMS) boasts its efficient architecture based on the Go language and powerful features, providing us with a flexible content management platform.{% diy %}How it helps us implement dynamic loading of custom media resources like image URLs, making website content operation more skillful.

The foundation of flexible content operation:{% diy %}The charm of tags

During the operation of a website, we often encounter such needs: we need to display a dynamically changing promotional image in a specific area of the website, or embed a video link that is always updated, or provide a PDF download address that can be replaced regularly.This content usually does not belong to conventional articles, product details, or category information, but is a customized element required for the global or specific page layout of the website.At this point, if each update requires modifying the template code, it is not only inefficient but also prone to introducing errors.

Of Security CMS{% diy %}The label is created to solve this pain point.It allows us to flexibly define various custom parameters in the background and dynamically call these parameters in the front-end template, achieving easy content management and updates.{% system %}(System settings) and{% contact %}(Contact information) and other tags focus on obtaining different preset system information, {% diy %}The positioning of the tag is more general, aiming to provide website operators with a highly free custom content management channel, allowing fragmented information that is not suitable for existing modules to be managed and utilized efficiently.

How to define custom media resources in the background?

To utilize{% diy %}Tag dynamically loads media resources, first you need to set these custom parameters in the Anqi CMS backend management interface.Although the document does not directly display an independent management module named "Custom Content", we can understand it by referring to the way custom parameters are added in "Global Settings" or "Contact Information Settings".Generally, you will find the option to 'Custom Parameters' or 'Add Custom Setting Items' on some settings page in the background (such as 'Background Settings' -> 'Global Settings' or 'Content Settings' etc.).

When adding custom parameters, you need to pay attention to the following key points:

  1. Parameter NameThe name used when calling this custom resource in the template, recommended to use concise and meaningful English characters, for examplehomePageBanner/promoVideoUrl/companyBrochurePdfetc.
  2. Parameter ValueHere is where you will store the link to the dynamic media resource.For example, a complete URL of an image, an iframe embed code for a video, a download link for a PDF file, and so on.
  3. RemarkThis is an optional field, used to describe the purpose of the parameter, convenient for future management and maintenance.

For example, if you want to place a main visual image that can be changed at any time on the homepage, you can set it in the background custom parameters:

  • Parameter Name:homePageHeroImage
  • Parameter value:https://yourwebsite.com/uploads/2023/10/new_hero_image.webp
  • Note: Homepage main visual image

This, a custom image URL resource is ready.

{% diy %}Tag: Magic wand in front-end templates

After defining the custom parameters in the background, we can use them in the frontend template.{% diy %}Tags to retrieve and display these dynamic resources.{% diy %}the basic usage of tags is{% diy 变量名称 with name="字段名称" %}.

  1. Dynamic loading of image URL

    Assuming we have already defined a parameter namedhomePageHeroImagewith the value of the image URL. In the template, we can call and display this image as follows:

    {% diy homeBannerImage with name="homePageHeroImage" %}
    <img src="{{ homeBannerImage }}" alt="网站首页主视觉" class="hero-section-banner">
    

    If the image may not exist, we can also use{% if %}tags for conditional judgment to increase the robustness of the template:

    {% diy homeBannerImage with name="homePageHeroImage" %}
    {% if homeBannerImage %}
        <img src="{{ homeBannerImage }}" alt="网站首页主视觉" class="hero-section-banner">
    {% else %}
        <img src="/static/images/default-banner.webp" alt="默认主视觉" class="hero-section-banner">
    {% endif %}
    

    Further considering performance optimization, if your custom image is the original large image and you want to load it as a thumbnail on the front end, Anqi CMS provides|thumbFilter. This means you don't have to manually upload thumbnails in the background, the system can dynamically generate them based on the original image:

    ”`twig {% diy homeBannerImage with name=“homePageHeroImage” %} {% if homeBannerImage %}

    <img src="{{ home
    

Related articles

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 types of 'custom content information' can I create in the background for the `{% diy %}` tag to call?

As an experienced website operations expert, I am well aware of how crucial it is to manage and call various contents flexibly in daily work.AnQiCMS (AnQiCMS) performs very well in this regard, it provides a series of powerful tags, making content operation effortless.Today, let's delve into it deeply. As a user of Anqi CMS, you can create what types of custom content information in the background, and call it flexibly in the front-end of the website through the `{% diy %}` tag.

2025-11-06

`{% diy %}` label and the system built-in `{% system %}` or `{% contact %}` label what are the similarities and differences?

AnQi CMS as an efficient enterprise-level content management system, its template tag system provides great flexibility for content display.When building a website, we often need to fetch various data from the backend and display it on the frontend page.Among these, `{% system %}`, `{% contact %}`, and `{% diy %}` are all used to obtain information from the background configuration, but they have subtle differences in functional emphasis, data source, and application scenarios.Understanding these similarities and differences can help us use these tools more efficiently and rationally, creating a clear structure

2025-11-06

How to implement a custom global website title or subtitle display using the `{% diy %}` tag?

## How to cleverly use the `{% diy %}` tag of AnQi CMS: Create personalized global website title and subtitle Maintaining brand image consistency and content update flexibility is crucial in website operation.Especially the global title and subtitle of the website, which are not only the first impression visitors have of the website content, but are also key elements of search engine optimization (SEO).

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 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 the `{% diy %}` tag support retrieving custom content created by the rich text editor and rendering it?

As an experienced website operation expert, and also a deep user of Anqi CMS, I am very happy to discuss with everyone the ability of the `{% diy %}` tag in processing 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.

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