As an experienced website operation expert, I know that effective content management and optimization are the key to success in the increasingly fierce online environment.AnQiCMS (AnQiCMS) leverages its high-performance architecture in Go language and flexible template system to provide us with an excellent content management experience.Today, let's delve into a topic that many operators and developers are concerned about: in{% jsonLd %}Can we nest other AnQiCMS template tags within a tag to dynamically generate content?
Of Security CMS{% jsonLd %}Tag: Unlock the nesting capability of dynamic JSON-LD content.
In modern SEO strategies, structured data (JSON-LD) plays a crucial role, helping search engines better understand page content and display richer snippets (Rich Snippets) in search results, significantly improving click-through rates. Anqi CMS is well-versed in this, providing{% jsonLd %}This powerful tag allows us to directly define the JSON-LD data of the page in the template.But how flexible is this tag? Does it allow us to nest AnQiCMS dynamic content tags within it to achieve highly automated content?
The answer is affirmative, absolutely! The template engine of AnQiCMS is beautifully designed, it supports syntax similar to the Django template engine, which means that in{% jsonLd %}Within the tag, 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 the order from top to bottom. For{% jsonLd %}In terms of tags, its processing process can be summarized into two main stages:
- Template tag rendering phase:First, AnQiCMS template engine will recognize and render
{% jsonLd %}and{% endjsonLd %}This includes all AnQiCMS template tags contained between these tags. This includes variable output tags such as{{ archive.Title }}Conditional judgment tags such as{% if ... %}Loop tags such as{% for ... %}And other functional tags. At this stage, all dynamic content will be parsed and replaced with actual data. - JSON-LD content processing phase:Template rendering completed,
{% jsonLd %}The remaining content within the tags, at this point it is a complete JSON string filled with static text and dynamic data. AnQiCMS will further process this JSON string, treating it as structured data for the page, and merge it with the system default generated JSON-LD (if there is a conflict, the custom content will usually override the default values), and finally use it as<script type="application/ld+json">The tag is 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 tags 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 and conforms to the **practice** of JSON-LD.{% system with name='BaseUrl' %}{{ archive.Logo }}Combined with the system's base URL and the article cover image URL, ensure the integrity of the image path. Note,{{ archive.Logo }}The variable usually outputs the URL directly, without additional|safeBecause the JSON string itself handles the escaping of internal quotes. *