As an experienced website operations expert, I know that effective content management and optimization are the key to success in the increasingly competitive online environment.AnQiCMS (AnQiCMS) provides an excellent content management experience with its high-performance architecture in Go language and flexible template system.{% jsonLd %}In the tag, can we nest other AnQiCMS template tags to dynamically generate content?
Anqi CMS's{% jsonLd %}Tag: Unlock the nesting capability of dynamic JSON-LD content
In modern SEO strategies, structured data (JSON-LD) plays a crucial role, which helps search engines better understand page content and display richer snippets (Rich Snippets) in search results, significantly increasing click-through rates. Anqi CMS is well-versed in this, and provides{% jsonLd %}This powerful tag allows us to define the JSON-LD data of the page directly in the template.But how flexible is this tag?Does it allow us to nest dynamic content tags of AnQiCMS to achieve high content automation?
The answer is affirmative, absolutely! The template engine design of AnQiCMS is exquisite, it supports syntax similar to Django template engine, which means that in{% jsonLd %}Tags inside, you can not only write static JSON structures, but also skillfully integrate various AnQiCMS template tags, dynamically filling JSON-LD data.This greatly liberates our productivity in fine-grained management and maintenance of structured data.
How does AnQiCMS handle nested tags
Understanding the internal working mechanism of AnQiCMS is crucial.When AnQiCMS's template engine parses the page, it processes all template tags in an order from top to bottom.{% jsonLd %}In terms of tags, its processing process can be summarized into two main stages:
- Template tag rendering stage:Firstly, the template engine of AnQiCMS will recognize and render
{% jsonLd %}and{% endjsonLd %}all AnQiCMS template tags between these tags. This includes variable output tags such as{{ archive.Title }})、condition judgment tag(such as{% if ... %})、loop tag(such as{% for ... %})and other function tags. At this stage, all dynamic content will be parsed and replaced with actual data. - JSON-LD content processing stage:Template rendering completed,
{% jsonLd %}标签内剩下的内容,此时已经是一个完整的、由静态文本和动态数据填充而成的JSON字符串。AnQiCMS会进一步处理这个JSON字符串,将其视为页面的结构化数据,并与系统默认生成的JSON-LD进行合并(如果存在冲突,自定义的内容通常会覆盖默认值),最终将其作为<script type="application/ld+json">Label embedded in the HTML of the page.
The essence of this processing mechanism lies in the fact that AnQiCMS's template engine has already assembled the JSON-LD data before generating the final HTML.Therefore, as long as the final rendered content conforms to the JSON format specification, any AnQiCMS template tag can be effectively utilized.
Actual application scenarios and examples.
This nested capability is of great value in actual operation. For example, for the detail page of a blog article, we can easily dynamically generate itsArticletype of JSON-LD:
{% jsonLd %}
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "{{ archive.Title }}",
"description": "{{ archive.Description | truncatechars:150 }}",
"image": [
"{% system with name='BaseUrl' %}{{ archive.Logo }}"
],
"datePublished": "{{ stampToDate(archive.CreatedTime, '2006-01-02T15:04:05-07:00') }}",
"dateModified": "{{ stampToDate(archive.UpdatedTime, '2006-01-02T15:04:05-07:00') }}",
"author": {
"@type": "Person",
"name": "{% system with name='SiteName' %}"
},
"publisher": {
"@type": "Organization",
"name": "{% system with name='SiteName' %}",
"logo": {
"@type": "ImageObject",
"url": "{% system with name='SiteLogo' %}"
}
},
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "{% system with name='BaseUrl' %}{{ archive.Link }}"
}
}
</script>
{% endjsonLd %}
In the above example, you will see:
{{ archive.Title }}/{{ archive.Description }}: Directly obtain the title and description from the current article details.truncatechars:150The filter ensures that the description string is not too long, in line with the **practices** of JSON-LD.{% system with name='BaseUrl' %}{{ archive.Logo }}:Combined with the system configuration website base URL and the article cover image URL, ensure the integrity of the image path. Note,{{ archive.Logo }}Variables are usually output directly to the URL without additional|safeEnglish because JSON string values themselves handle the internal quote escaping. *