`{% Ld %}` tag supports `with` variable assignment to organize complex Json-LD content?

Calendar 👁️ 95

As an experienced website operations expert, in the practice of AnQiCMS (AnQiCMS), we deeply understand the importance of structured data (Schema.org Markup) for modern SEO.It is not only to make search engines better understand your content, but also to enhance the display form of the website in search results and obtain the key to "rich media abstracts".Today, let's delve deeply into a common problem encountered in the development of Anqi CMS templates:{% jsonLd %}Does the tag supportwithVariable assignment to organize complex Json-LD content?

Of Security CMS{% jsonLd %}Tag: The foundation of structured data

In AnQi CMS,{% jsonLd %}Tags provide us with a powerful ability to embed and manage JSON-LD structured data directly in templates.According to the AnQiCMS design document, the purpose of this tag is very clear: it allows developers to insert custom JSON-LD content, and the system will intelligently merge these custom contents with the structured data generated by AnQiCMS by default.If there is a conflict, your custom content will take precedence over the default item, which brings us great flexibility.

For example, the most basic one{% jsonLd %}The label usage may be like this:

{% jsonLd %}
<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "WebPage",
  "name": "安企CMS官网",
  "url": "https://en.anqicms.com"
}
</script>
{% endjsonLd %}

This method is simple and clear, suitable for structured data content that is relatively fixed or less.However, in actual operation, our structured data often needs to be dynamically generated according to page content (such as article titles, product prices, author information, etc.) and may contain complex nested structures.At this point, if all the content is hardcoded in the JSON string, not only will the code become long and difficult to maintain, but it will also greatly reduce the reusability of the template.

withLabel: flexible definition of template variables

The Anqi CMS template engine (based on Django template engine syntax) provides{% with %}Label, this is a very practical tool used to declare and assign variables temporarily in templates.Its main purpose is to improve the readability and maintainability of templates, avoiding repeated calculations or passing complex expressions. ThroughwithVariables defined by the tag are limited to{% with %}and{% endwith %}between, which can carry strings, numbers, and even complex objects returned by other tags.

A typicalwithThe usage scenario of the tag may be like this:

{% with pageTitle="安企CMS深度解析" pageKeywords="AnQiCMS, Json-LD, 结构化数据" %}
  <title>{{ pageTitle }}</title>
  <meta name="keywords" content="{{ pageKeywords }}">
{% endwith %}

Here, pageTitleandpageKeywordsVariables are defined and used for subsequent output, making the code logic clearer.

Skillfully combined:withwith{% jsonLd %}in-depth collaboration

Then, let's go back to our core question:{% jsonLd %}Does the tag supportwithAssign variables to organize complex Json-LD content?

The answer is affirmative, and this is exactly the practice of building high-quality, maintainable Json-LD structured data!

The template engine of AnQi CMS is processing{% jsonLd %}When the content inside the tag is parsed, it is treated as ordinary template content. This means that as long as you in{% jsonLd %}the closing block of the tag (i.e.,<script type="application/ld+json">The template variable syntax (such as{{ variableName }}) is used inside the tag, the template engine will replace these variables with their corresponding values before outputting.

By{% with %}tags, we can pre-select from{% archiveDetail %}/{% system %}/{% contact %}Extract the required information from the built-in data tags of AnQiCMS, or perform some preliminary data processing, and then assign the processed data towithvariables. Subsequently,{% jsonLd %}The JSON structure inside the tag, directly quote thesewithvariables only.

Let's experience the power of deep collaboration through a specific example: Suppose we need to generate a product article that includes the name, description, image, price, and number of comments for the product.ProductSchema.

{# 1. 使用with标签定义变量,从文章详情中提取所需数据 #}
{% with 
    productName=archive.Title 
    productDescription=archive.Description 
    productImage=archive.Logo 
    productPrice="99.99" {# 假设价格字段为字符串,或从自定义字段中获取 #}
    reviewCount=archive.CommentCount 
    productUrl=archive.Link 
    currency="CNY"
%}

{% jsonLd %}
<script type="application/ld+json">
{
  "@context": "https://schema.org/",
  "@type": "Product",
  "name": "{{ productName }}",
  "image": "{{ productImage }}",
  "description": "{{ productDescription|truncatechars:150 }}", {# 可以对描述进行截断处理 #}
  "sku": "AQ-CMS-001", {# 示例SKU #}
  "offers": {
    "@type": "Offer",
    "url": "{{ productUrl }}",
    "priceCurrency": "{{ currency }}",
    "price": "{{ productPrice }}",
    "itemCondition": "https://schema.org/NewCondition",
    "availability": "https://schema.org/InStock"
  },
  "aggregateRating": {
    "@type": "AggregateRating",
    "ratingValue": "4.5", {# 示例评分,实际应动态获取 #}
    "reviewCount": "{{ reviewCount }}"
  }
}
</script>
{% endjsonLd %}

{% endwith %}

In this example, we first go through a{% with %}Code block, assign the title, description, image URL, price, and number of comments of the article to easily understandable variables. Then, in{% jsonLd %}Labels inside, these variables are seamlessly embedded in the JSON-LD structure. This way, even if the content of the article changes, we only need to ensurearchive.TitleCorrectly obtaining data fields, Json-LD will automatically update, greatly enhancing the dynamism and maintenance efficiency of the template.

Consideration and **practice in action

  1. Integration of data sources: {% with %}The power of tags lies in their ability to aggregate data from different AnQiCMS tags. You can{% archiveDetail %}get article information from{% categoryDetail %}get category information, even from{% system %}and{% contact %}Retrieve the global settings and contact information of the site, then organize them in a block, and finally inject them into Json-LD.withBlock, and finally inject them into Json-LD.
  2. JSON-LD syntax verification:Although AnQiCMS template engine handles variable replacement, the final Json-LD content still needs to strictly follow the Schema.org specification.Make sure to use the Google Structured Data Testing Tool or other online validators to check the validity of the Json-LD you generate, to avoid incorrect parsing by search engines due to syntax errors.
  3. URL path processing:All URLs (such asimage/urlfields) should usecomplete absolute pathsincludinghttp://orhttps://This is crucial for the proper crawling and understanding by search engines. AnQiCMS'sitem.LinkThe field usually returns a relative path, you may need to use `{% system with name=“BaseUrl”}

Related articles

If AnQiCMS supports introducing external data in Json-LD?

As an experienced website operations expert, I am well aware of the importance of structured data in the increasingly complex search engine environment.It is not only a tool to enhance the visibility of a website, but also the key to help search engines understand the content of web pages and display richer search results (Rich Snippets).Json-LD is the mainstream way to implement structured data, and its flexibility and powerful functions are highly praised.

2025-11-06

How to add a user's `reviews` or `rating` information in Json-LD?

## Merging user reviews and rating information cleverly into Json-LD structured data in Anqi CMS As a senior website operations expert, I am well aware of the importance of structured data in the context of today's search engine optimization (SEO). It not only helps search engines understand web content more accurately but also helps our website win attractive 'rich snippets', such as displaying product star ratings or the number of user comments directly in search results, which is undoubtedly a benefit for increasing click-through rates and user trust.

2025-11-06

How to generate `VideoObject` type Json-LD for AnQiCMS video page?

As an experienced website operation expert, I am well aware that how to make our content stand out in today's explosion of content on the Internet and be better understood and recommended by search engines is the key to the success of website operation.Video content, as a popular media form, plays a particularly important role in SEO optimization.Today, let's delve into how to take advantage of the powerful features of AnQiCMS to generate high-quality `VideoObject` type Json-LD for video pages, thereby improving the visibility and search ranking of video content.

2025-11-06

How to use the information in the AnQiCMS backend settings to add `Organization` or `WebSite` types to Json-LD?

As an experienced website operation expert, I am well aware of the importance of structured data for a website's performance in search engines.Json-LD is the mainstream way to implement structured data, which can help search engines better understand website content, thereby enhancing the display opportunities of websites in search results, such as obtaining rich search results (Rich Snippets).

2025-11-06

What Schema.org types are commonly used in the development of AnQiCMS?

In today's digital marketing battlefield, the visibility and content understanding of a website are crucial to the success of enterprises and self-media operators.AnQiCMS (AnQiCMS) is an efficient content management system based on the Go language, which not only provides powerful content publishing and management capabilities, but also has put a lot of effort into SEO optimization.Among them, structured data, especially the Schema.org tags implemented through JSON-LD format, are important tools to help search engines deeply understand the content of websites and improve search rankings.

2025-11-06

How to get the canonical URL of the current page in Json-LD?

AnQi CMS, as an enterprise-level system that specializes in content management, always makes every effort to improve the website's SEO performance.We know that it is crucial to clearly and accurately convey website information to search engines in the context of increasingly refined search engine algorithms.Amongst them, the clever combination of the规范链接(`canonical URL`)and structured data(JSON-LD)is a tool to optimize website visibility and avoid the penalty of duplicate content.

2025-11-06

Does the URL path in Json-LD automatically adapt to AnQiCMS's pseudo-static settings?

AnQiCMS as an enterprise-level content management system focusing on SEO optimization, its pseudo-static (URL rewriting) function is undoubtedly one of the core strategies to enhance the search engine friendliness of the website.While Json-LD plays a crucial role as an important carrier of structured data in modern SEO.So, in Anqi CMS, can the URL path of Json-LD content automatically adapt to the website's pseudo-static settings?This is the issue that many operators and developers are concerned about.

2025-11-06

How to integrate AnQiCMS category detail information (such as category name, description) into Json-LD?

As an experienced website operations expert, I am well aware that it is crucial to understand how to make our website content better understood and presented by search engines in the increasingly fierce online environment.Structured data (JSON-LD) is a powerful tool at our disposal, helping search engines parse page information more accurately, thereby giving us the opportunity to present richer search results and attract more users' attention.

2025-11-06