How to generate random text for testing in the AnQiCMS template?

Calendar 👁️ 84

As an experienced website operations expert, I am well aware that during the website development and content testing phase, we often encounter the dilemma of a clever woman who cannot cook without rice - lacking real content to fill the page in order to verify design, layout, and functionality.Especially for operators and developers who use powerful and flexible content management systems like AnQiCMS (AnQiCMS), efficiently simulating content is the key to improving work efficiency.

AnQi CMS with its high-performance architecture based on Go language, flexible content model, and Django-like template engine syntax, provides great convenience for content management.When designing templates, developing front-end interfaces, or testing new features, we can never always wait for real content to be in place.How to quickly generate random test text in the AnQiCMS template has become a common concern.

Why do we need to generate random text in the template?

Before delving into "how to do

  1. Verify design and layout: When the content has not been determined, random text can help designers and front-end developers fill the page, intuitively check whether the layout is reasonable, whether the spacing between elements is coordinated, and how responsive design performs on different devices.Avoided the embarrassment of finding that the design does not match the content when it comes.
  2. Test content model and display effectsThe "Flexible Content Model" feature of AnQiCMS allows us to customize various fields.When testing new content types (such as articles, products, events, etc.), using random text can quickly simulate a variety of text lengths and paragraph counts to ensure that the display effect of the content on the front end meets expectations and does not result in overflow or chaotic layout issues.
  3. Enhance development efficiency:No need to manually input a large number of meaningless characters or copy and paste repetitive content, which greatly saves test time and allows developers to focus more on function implementation and bug fixing.
  4. Avoid 'placeholder fatigue'The traditional placeholders like “Enter content here” or “xxxxxxxx” often disturb the visual, while the random text in the style of Lorem Ipsum, due to its similar structure to real text, can provide a more closely approximated visual experience to the ultimate user.

Random text generator in AnQi CMS template:loremTag

AnQi CMS template engine deeply understands the needs of developers and operators, and built-in a very practical tag -loremUsed specifically to generate random text. This tag's usage is very concise and intuitive, meeting our testing needs in various scenarios.

loremThe basic syntax of the tag is:{% lorem 数量 方法 random %}Let's interpret these parameters one by one.

  • 数量(Number)This parameter is used to specify how many units of random text you want to generate. What the 'unit' specifically is, is determined by the next parameter——方法——to decide.
  • 方法(Method)This is the definition数量The key of the unit.
    • wRepresents 'words' (word). If you usewthen数量The parameter will specify how many random words to generate.
    • pIt represents "paragraphs" (paragraphs). If you usepthen数量The parameter specifies how many random paragraphs to generate.
    • If方法The parameter is not filled in,loremThe label will generate a standard Lorem Ipsum text by default, which is long enough to fill most page blocks.
  • random(Randomness)This is an optional parameter. If addedrandomThe system will randomly select text fragments from the entire Lorem Ipsum corpus to generate, rather than cutting from the beginning in order.This is very useful for simulating more diverse content layouts.

Actual operation example

Let us feel through several specific examplesloremThe strong and convenient of tags."),

1. Generate a random text of default length

This is the simplest usage, just use it directly when you need to quickly fill an area without any special requirements for length.

Template code:

<div class="content-block">
    {% lorem %}
</div>

Possible output (excerpt):

<div class="content-block">
    Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>

2. Generate a specified number of random words

If you need to simulate concise titles, summaries, or tags,wthe method will be very practical.

Template code:

<h3>{% lorem 8 w %}</h3>
<p class="summary">{% lorem 20 w random %}</p>

Possible output (excerpt):

<h3>Lorem ipsum dolor sit amet, consectetur adipisici elit,</h3>
<p class="summary">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.</p>

Please note that in the second example, we addedrandomThe parameter makes the generated text different each time the page is refreshed, which helps to fully test the layout flexibility.

3. Generate a specified number of random paragraphs

For areas that need to be filled with multiple paragraphs, such as article content and product descriptions, usepa method that can efficiently generate structured text.

Template code:

<article>
    <h2>文章标题占位符</h2>
    {% lorem 3 p %}
</article>

Possible output (excerpt):

<article>
    <h2>文章标题占位符</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    <p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
    <p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
</article>

combined with other template tags for advanced testing

loremThe tag itself is already powerful, but combined with the other features of the AnQiCMS template engine, we can achieve more refined test scenarios.

  • Control the output length: AlthoughloremYou can specify the number of words or paragraphs, but sometimes we may need to control the character length more accurately, such as setting a fixed character number for SEO descriptions. In this case, you can use a string filter liketruncatechars(Truncate to specified character length) ortruncatewords(Truncate to specified word count).

    {% set placeholder_text = lorem(50, 'w') %} {# 生成50个单词 #}
    <meta name="description" content="{{ placeholder_text|truncatechars:150 }}">
    

    Here we first useloremGenerate a text and assign it toplaceholder_textThen proceedtruncatecharsThe filter truncates it to 150 characters, which is very suitable for testing SEO fields.

  • Generate different content in a loop.If your layout has multiple repeated modules, each module needs different random text, you can make use offorloop andrandomthe combination of parameters.

    {% for i in range(1, 4) %} {# 循环3次 #}
        <div class="product-item">
            <h4>产品标题 {{ i }}:{% lorem 5 w random %}</h4>
            <p>{% lorem 20 w random %}</p>
        </div>
    {% endfor %}
    

    This, each loop will generate a different random text, simulating the real content of multiple products or articles.

  • Image placeholder: AlthoughloremLabels only generate text, but placeholders are also important in visual design. Although AnQiCMS does not have a built-in placeholder feature for images, we can combine external services such asLorem PicsumorPlaceholder.comSimulate an image.

    <img src="https://en.anqicms.com/uploads/202511/07/84191bf14f7dc401.webp" alt="随机图片">
    

Related articles

How to define and use variables (set, with) in AnQiCMS templates?

Mastery in AnQiCMS templates: Unlocking the Power of Variables (Deep Analysis of set and with) As an experienced website operations expert, I know that a flexible and efficient content management system is crucial for the success of a website.AnQiCMS with its concise and efficient architecture and support for Django template engine syntax, provides us with great convenience.In template development, being proficient in variable definition and assignment is undoubtedly the key to enhancing template flexibility and maintainability.

2025-11-07

How to format timestamp display in AnQiCMS template?

As an experienced website operation expert, I am well aware that the timeliness and presentation of content are crucial to user experience.In an efficient content management system like AnQiCMS, even a seemingly simple date display contains operational wisdom to enhance the professionalism and readability of the website.Today, let's delve into how to beautifully transform the original timestamps into user-friendly date formats in the AnQiCMS template.

2025-11-07

What are the common filters supported by AnQiCMS for processing template data (such as string truncation, date formatting)?

In the Anqi CMS template world, data is not just raw text or numbers, they are the foundation of excellent website content.However, the original data often needs to be polished before it can present itself in a certain posture to the user.At this time, the template filter has become an indispensable helper to us.They are like a Swiss Army knife for data processing, capable of performing various transformations, formatting, and refining template variables, bringing new luster to the data and meeting all kinds of display needs.As an experienced website operation expert

2025-11-07

How to implement nested category display in AnQiCMS template

As an experienced website operations expert, I am well aware of the value of a flexible and efficient content management system for the success of a website.AnQiCMS (AnQiCMS) relies on its high-performance architecture based on the Go language and the Django-style template engine, bringing great convenience and infinite possibilities to content display.Today, let's delve into a very common requirement in actual operation: how to implement nested display of multi-level categories in AnQiCMS templates, making your website structure clearer and enhancing the user experience.

2025-11-07

Where should the AnQiCMS template files be placed?

## Unveiling the Home of AnQiCMS Templates: Clear Guidance Helps You Customize Easily As an experienced website operations expert, I am well aware of the importance of a flexible and efficient content management system for businesses.AnQiCMS is an excellent platform developed based on the Go language, which not only wins the favor of many users with its high performance and high concurrency features, but also provides great convenience in customization.For operators and developers who want to fully utilize their customization potential and build personalized websites, clearly defining the storage directory of AnQiCMS template files is the first step towards success.

2025-11-07

How to define an AnQiCMS template configuration file (config.)?

As an experienced website operations expert, I fully understand the importance of a flexible and powerful content management system for enterprises.AnQiCMS is an excellent platform committed to providing efficient and customizable solutions.In the template ecosystem of AnQiCMS, a seemingly insignificant but powerful file - `config.`, plays a crucial role.It not only defines the basic attributes of the template, but also profoundly affects the behavior and performance of the template in the system.

2025-11-07

How does the AnQiCMS template support adaptive, code adaptation, and PC+mobile mode?

## AnQiCMS template: How to ride the multi-end content display with wisdom and flexibility?In today's fast-paced digital world, it is common for users to access websites through various devices.As experienced website operators, we know that whether a website can provide a smooth and high-quality experience on PCs, tablets, mobile phones, and other terminals is directly related to user retention and business conversion.

2025-11-07

How to set a custom template for the document detail page or category list page of AnQiCMS?

As an experienced website operations expert, I am well aware that the flexibility and customizability of a content management system (CMS) are crucial for the long-term development of the website and the user experience.AnQiCMS (AnQiCMS) provides an excellent solution in this aspect with its powerful functions and ease of use.Today, let's delve into how to set up custom templates for your document detail page or category list page in AnQiCMS, making your website content display more personalized and professional.

2025-11-07