How to quickly fill a large amount of virtual content in the template without manual input?

Auto CMS Template Development Acceleration Secrets: The Wisdom of Quickly Filling a Large Amount of Virtual Content

In the world of website operations and development, efficiency is always the core competitive advantage.特别是当我们投入大量精力设计和开发一套精美的网站模板时,最常见的挑战之一便是如何快速填充足够多的内容,以便在真实数据加载前,就能全面审视布局、样式和交互是否符合预期。Manual input of a large amount of test data is undoubtedly time-consuming and labor-intensive, and may even disrupt our creative rhythm.

As an expert who is deeply familiar with the various functions and content operation strategies of the Aanqi CMS, I fully understand this pain point.AnQiCMS (AnQiCMS) is an enterprise-level content management system developed based on the Go language, which not only has the advantages of high efficiency, customization and easy expansion for small and medium-sized enterprises and content operation teams, but also provides many conveniences at the template design level, including the powerful function of quickly filling virtual content in the template.Today, let's delve into how to easily implement content 'one-click filling' in the Anqi CMS template, saying goodbye to cumbersome manual input.

Say Goodbye to Manual Input: The Uses of LOREM Tags

The template engine of AnQi CMS is compatible with Django template syntax, which means we can take advantage of its built-in powerful tags to simplify development. When it comes to quickly filling virtual content, the first priority islorem标签——它就像一位魔法师,能够根据我们的指令,瞬间生成指定长度的随机英文文本。

Imagine that you are designing the layout of an article detail page, and you need a long article content to test the layout effect. At this time, you don't have to strain your brain to copy and paste real text, just simply add it to the template.{% lorem %}标签。这个标签默认会生成一个完整的随机拉丁文段落,非常适合作为文章正文的占位符。

What's even better is,loremLabels provide various parameters that allow us to precisely control the number and type of generated text according to specific needs:

  • Generate a specified number of words:If you only need a text composed of a specific number of words, like an article summary, you can use it like this:{% lorem 10 w %}Here,10It indicates the number of words.wRepresents "words" (words).
  • Generate a specified number of paragraphs:When you need multiple continuous text segments to simulate multiple paragraphs on a page,{% lorem 3 p %}it can come in handy, generating 3 independent paragraphs.pRepresents the "paragraphs" (paragraphs).
  • Enhanced randomness:If you want the generated text content to be different each time you refresh the page, increaserandomthe parameters:{% lorem 100 w random %}.

PassloremLabels, we can quickly fill in temporary content for article titles, summaries, and main text sections, ensuring that we can preview the visual effects and layout structure of the template even without actual data.

Fill list content: Combine loop and data tags

It is not enough to fill a single block of content to simulate a complete website.A well-rounded website template often needs to display dynamic content such as article lists, product lists, and category navigation.archiveList(Document List),categoryList(category list),pageList(Single page list) etc. data tags, they can help us obtain and display real (or virtual) data sets. Combined with the template engine,forLoop tags, we can easily build dynamic list layouts.

For example, on a list page of articles, you may need to display thumbnails of multiple articles, titles, descriptions, and publishing times. Although we do not have real 100 articles yet, we can make use ofarchiveListTagslimitParameters to limit the number of "articles" obtained, combined withforloop andloremTags to simulate the details of each article:

{# 假设我们正在文章列表页,并想展示10篇文章的模拟内容 #}
<div>
    {% archiveList archives with type="list" limit="10" moduleId=1 %} {# 获取文章模型下10条文档,moduleId=1通常代表文章模型 #}
        {% for item in archives %}
        <div class="article-item">
            <a href="{{ item.Link }}" class="article-link">
                {% if item.Thumb %} {# 如果文章有缩略图(即使是占位图),就显示 #}
                    <img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="article-thumb">
                {% else %}
                    {# 否则可以显示一个默认的占位图 #}
                    <img src="/static/images/placeholder.jpg" alt="默认占位图" class="article-thumb">
                {% endif %}
                <h3 class="article-title">{{ item.Title|default("这里是虚拟文章标题") }}</h3> {# 如果没有真实标题,显示虚拟标题 #}
            </a>
            <p class="article-description">
                {# 使用lorem标签生成文章简介的虚拟内容 #}
                {% lorem 30 w random %}
            </p>
            <div class="article-meta">
                {# 格式化时间戳,模拟发布时间 #}
                <span class="publish-date">{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                <span class="views">阅读量: {{ item.Views|default(0) }}</span>
            </div>
        </div>
        {% empty %}
        {# 如果没有获取到任何数据,显示提示信息 #}
        <p>当前没有任何文章内容可供显示。</p>
        {% endfor %}
    {% endarchiveList %}
</div>

In this example,archiveListWill try to retrieve 10 articles of data. Even if there are not that many real articles in the database,item.Titleanditem.CreatedTimefields exist by default (even if they are empty), we can still accessdefaultThe filter provides alternative text andloremgenerates a description.item.ThumbThen it can determine if there is a thumbnail and display the actual image or placeholder accordingly.stampToDateThe label can also format timestamps into readable dates, making virtual data appear more realistic.

In a similar manner, we can also quickly simulate a classified list (categoryList), a single-page list (pageListEnglish support for complex structures such as )et al., providing comprehensive data support for template design.

Simulate complex scenarios: flexibly use filters and condition judgments

To make virtual content more persuasive, we can also combine the various filters (Filters) and conditional judgments (If Else) provided by the Anqi CMS template engine to simulate more complex display logic.

For example,truncatecharsThe filter can help us truncate long texts, simulating a fixed length for article summaries;randomThe filter can add randomness to different virtual contents, avoiding visual monotony; andifThe label can be rendered or not based on certain conditions (such as whether the image exists, or if a certain field has a value).

Assuming we want the length of the article description to vary and some articles may not have thumbnails:

<p class="article-description">
    {# 使用truncatechars截取lorem生成的文本,模拟不同长度的描述 #}
    {% lorem 50 w random | truncatechars: (30 + forloop.Counter * 5) %}
</p>
{# 配合if判断,如果item没有Logo(首图),则不显示图片区域 #}
{% if item.Logo %}
    <img src="{{ item.Logo }}" alt="{{ item.Title }}" class="article-logo">
{% else %}
    <span class="no-logo-text">无封面图</span>
{% endif %}

Here, we cleverly integrateforloop.Counter(Loop count) withtruncatecharsCombine, allowing each article description to have a slightly different length, increasing authenticity. At the same time,if item.Logothen demonstrates how to flexibly adjust the display of the template based on whether the data exists.

When debugging templates, if you want to understand the complete structure and value of a variable,dumpfilters are your good helper. For example,{{ item|dump }}It will outputitemThe detailed information of variables, which is very helpful for understanding data structures and troubleshooting.

Supplementary strategy for batch importing of content

AlthoughloremLabel and data list labels can quickly fill virtual content for template testing, but sometimes we may need more structured and closer to real business logic virtual data, such as testing pagination effects, filtering functions, or displaying data after users submit forms. At this time, the 'Content Collection and Bulk Import' feature of Anqi CMS becomes a powerful