In the operation practice of AnQiCMS (AnQiCMS), structured data (usually presented in the form of Json-LD) plays a vital role.It can help search engines better understand the content of the page, leading to richer search results (Rich Snippets), and significantly improve the visibility and click-through rate of the website.However, the writing and integration of Json-LD are not a one-time task, especially at the template level, where we often need to fine-tune its output content to ensure the accuracy and integrity of the data.

AnQi CMS is a system designed specifically for content operators and SEO-friendly, naturally understanding this path.It not only integrates the basic structured data output mechanism, but also provides flexible template tags, allowing operators and developers to deeply customize the content of Json-LD.Next, let's delve into how to debug the output content of Json-LD in AnQiCMS templates.

Understand the Json-LD mechanism of AnQiCMS

Firstly, we need to understand the basic way of handling Json-LD by AnQi CMS. According to the document description, when the structured data feature is turned on in the background, the system will default to insert one<script type="application/ld+json"></script>Label, which contains basic structured data. This saves us the work of starting from scratch.

But what truly gives us flexible control is the Anq CMS provided.{% jsonLd %} ... {% endjsonLd %}Template tag. This tag allows us to define or modify Json-LD content directly in the template. Its cleverness lies in the fact that if you are{% jsonLd %}The tag writes a custom Json-LD field, and Anqi CMS will automatically merge it with the default output data of the system.If your custom field conflicts with the default field, your custom content will override the system default value, which provides us with powerful customization capabilities.

Why do you need to debug Json-LD?

Even though AnQiCMS provides an intelligent merging mechanism, debugging Json-LD is still an indispensable step. The reasons are usually as follows:

  1. Syntax errorThe essence of Json-LD is JSON format, any missing comma, quote, or bracket can cause the entire structured data to fail.
  2. The content is inaccurate.The system default or the data we manually fill may not match the actual content on the page, or some key fields may be missing.
  3. Mismatched patternWe expect to generate specific types of Rich Snippets (such as articles, products, comments, etc.) for the page, but the actual output Json-LD may not meet the requirements of the corresponding Schema.org types.
  4. Priority issue: Sometimes a page may have multiple structured data sources, and we need to ensure that the Json-LD output by AnQiCMS has the correct priority and does not conflict with other data sources.
  5. Search engine verification failed: Google and other search engines provide structured data testing tools, debugging is to ensure that the final output can pass these tools verification.

Build and modify Json-LD content in the template

To debug Json-LD, we first need to find or create it in the template. The template files of Anqi CMS are usually located/templateUnder the directory, and use syntax similar to Django template engine. For example, the article detail page might bearticle/detail.htmlor directly inbase.htmlto define common structures.

We can use in the page's<head>area,{% jsonLd %}Label to wrap our Json-LD code:

{% jsonLd %}
<script type="application/ld+json">
{
    "@context": "https://schema.org",
    "@type": "Article",
    "headline": "{% archiveDetail with name='Title' %}",
    "description": "{% archiveDetail with name='Description' %}",
    "image": [
        "{% archiveDetail with name='Logo' %}"
    ],
    "datePublished": "{{ stampToDate(archive.CreatedTime, "2006-01-02T15:04:05Z07:00") }}",
    "dateModified": "{{ stampToDate(archive.UpdatedTime, "2006-01-02T15:04:05Z07: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' %}"
        }
    }
}
</script>
{% endjsonLd %}

In the above example, we utilized various tags provided by AnQiCMS to dynamically populate Json-LD data:

  • {% archiveDetail with name='Title' %}Get the article title.
  • {% archiveDetail with name='Description' %}Get the article description.
  • {% archiveDetail with name='Logo' %}Get the article thumbnail as an image.
  • {{ stampToDate(archive.CreatedTime, "2006-01-02T15:04:05Z07:00") }}and{{ stampToDate(archive.UpdatedTime, "2006-01-02T15:04:05Z07:00") }}Format the publish and update time.
  • {% system with name='SiteName' %}and{% system with name='SiteLogo' %}Get the website name and Logo.

These tags ensure that the Json-LD data is synchronized with the actual content of the current page.

The core tool for Json-LD debugging:dumpFilter

During the debugging of Json-LD,dumpThe filter is undoubtedly one of the most powerful tools provided by AnQi CMS. Its purpose is to print the structure type and value of variables, which is crucial for understanding the data flow and troubleshooting.

How to usedumpHow to debug Json-LD? We can't directlydumpthe whole<script type="application/ld+json">tag, because the Json-LD data has been wrapped. We should construct Json-LD'sDuring, performing on key variablesdump.

For example, if you suspect that the article title or description has not been correctly obtained, you can do it first in the Json-LD constructiondumpThese variables:

”`twig {# Assume we are on the article detail page, the archive object is available in the context #} {% set articleTitle = archive