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
- 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.
- 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.
- 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.
- 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: Although
loremYou 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 use
loremGenerate 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 of
forloop 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: Although
loremLabels 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="随机图片">