How to display a single-page slideshow (Images) in a frontend template?

As a senior security CMS website operation personnel, I am well aware of how to efficiently produce high-quality content using the system functions and present it elegantly on the front end.How to display a slide group image (Images) in a single-page front-end template?This question is exactly the advantage of Anqi CMS in content display flexibility.By the following article, I will give you a detailed explanation of how to implement this feature in the front-end template, helping you enhance the visual appeal of your website.

Understanding the storage of single-page and slide group images

In AnQi CMS, a single page (such as "About Us", "Contact Us", etc.) is not just a carrier of static text, it also has rich content management capabilities.This includes setting the page title, description, content, as well as the focus of our discussion this time - 'Banner image' or 'slide group image'.When you edit a single page in the Anqi CMS backend, the system provides the function to upload multiple images as a slideshow for the page.These images are stored and managed as an image array in the background.

Determine the location of the front-end template file

Firstly, we need to clarify where the front-end template file of the single page is located. According to the template production conventions of Anqi CMS, the default template for a single page is usuallypage/detail.htmlIn addition, the system also supports specifying a custom template for a specific single page, the naming format can bepage/detail-{单页ID}.htmlor directly specifying a custom template file path in the background (for examplepage/about.html)。No matter which template file you use, the core image loop display logic will be implemented in this file. Static resources such as style and script files are stored separately./public/static/directory.

UsepageDetailLabel to get image data

Anqi CMS provides powerful template tags, among whichpageDetailLabel specifically used to get detailed information of a single page. To access the uploaded slide group image on a single page template, we will usepageDetailLabel and specify itsnameparameters forImages.

ImagesThe field returns an array of image URLs. You can retrieve this image data in your single-page template in the following way:

{% pageDetail pageImages with name="Images" %}

Here, we define a variablepageImagesTo receivepageDetailLabel the image data obtained from the current single page. If you need to retrieve images from a specific ID page, you can addid="页ID"Parameter.

At the same time, in order to provide a good user experience and search engine optimization for slides, we usually also need to obtain the title of a single page as the image'saltproperty. This can also be usedpageDetailtags to implement:

{% pageDetail pageTitle with name="Title" %}

UtilizeforLoop through the image group tags

Get the image arraypageImagesAfter that, the next step is to display it in a front-end template. The template engine of Anqi CMS supportsforLoop tags, which make it very simple and intuitive to traverse array data.

The following code snippet shows how to combinepageImagesandpageTitlevariables to build a basic image slideshow HTML structure:

<div class="slideshow-container">
    {% pageDetail pageTitle with name="Title" %}
    {% pageDetail pageImages with name="Images" %}
    {% for imageUrl in pageImages %}
    <div class="mySlides fade">
        <img src="{{ imageUrl }}" alt="{{ pageTitle }}" style="width:100%">
    </div>
    {% empty %}
    <p>当前单页面没有配置幻灯片图片。</p>
    {% endfor %}
</div>

In this structure,slideshow-containerIt is the external container of the slide. Each image is wrapped in onemySlides fadeofdiv, among whichimageUrlis the URL of the current image in the loop processpageTitleand is used asaltThe attribute enhances the accessibility and SEO-friendliness of the image.{% empty %}Tags are a very practical feature that allows you to inpageImagesAn alternative content is displayed when the array is empty to avoid blank pages.

Dynamic slide show effect implemented with front-end technology.

The template code has successfully rendered all slide images on a single page to HTML.However, to implement dynamic slide effects such as automatic image switching, navigation buttons, or indicators, it is usually necessary to combine front-end JavaScript and CSS.

You can link external CSS and JS files in the template file, for example:

<link rel="stylesheet" href="{% system with name="TemplateUrl" %}/css/slideshow.css">
<!-- ... 其他内容 ... -->
<script src="{% system with name="TemplateUrl" %}/js/slideshow.js"></script>

Inslideshow.cssDefine the layout and transition effects of slides, such as setting image width, height, hiding inactive images, and transition animations. Whileslideshow.jsIn Chinese, you will write JavaScript code to control the slide transition logic, including automatic playback, click events for the previous/next buttons, and the status update of the bottom indicator.These frontend logic will act on the HTML structure generated by AnQiCMS template tags, thus completing a complete dynamic slide group display.

Summary and **practice**

BypageDetailTag to get the URL array of a single-page slide group image and utilizeforThe loop tag is used to iterate and display in front-end templates, which is the standard method for AnQiCMS to implement the single-page slide show function.

In actual operation, to achieve **effect, it is recommended that you:

  • Image optimization: When uploading images, try to use compressed and optimized images, or take advantage of the WebP format conversion and image automatic compression feature provided in the content settings of AnQiCMS to improve page loading speed.
  • Responsive DesignEnsure your CSS allows slides to display well on various devices (PC, mobile, tablet).
  • SEO-friendlyAlways add meaningful descriptions to slide images.altThe attribute will help search engines understand the image content and improve the page's SEO performance.

Master this skill, and you will be able to create single-page content with more visual impact and user attraction for your AnQiCMS site.

Frequently Asked Questions (FAQ)

Q1: What will the front end display if my single page does not upload a slide set?A1: If you use the code example in the article{% empty %}The tag, then whenpageImagesWhen the variable is empty (i.e., no image is uploaded), the template will display{% empty %}Content defined in the block, such as “No slide image is configured for the current single page.”. If not used{% empty %}Then the loop body will not render any content, the slide area may be blank.

Q2: Can I use different slide JS/CSS libraries to achieve the effect?A2: It is completely okay. The Anqi CMS front-end template is mainly responsible for generating HTML structures containing image URLs.As for the slide effect itself (such as image transition animation, navigation arrows, pagination indicators, etc.), it completely depends on the front-end JavaScript library and CSS style you choose.You just need to ensure your HTML structure (for exampledivNested,classThe name) should match the structure required by the frontend library you are using.

Q3: How to display different slide styles on different single pages?A3: If you want to apply a unique slide style or layout to a specific single-page application, you can specify a custom template file in the "Single Page Template" field while editing the single page in the background, for examplepage/custom-slideshow.html. In this custom template, you can write customized HTML structure for this page, introduce specific CSS/JS files to achieve personalized slide show display.