How to include json-ld data in eleventy? #4285
|
Hi, I am using the 11ty / eleventy-base-blog at: I am trying to add some basic json-ld to pages. In an include .njk file that is included in base.njk I have tried: and and and none of them are outputted. I also tried this directly in base.njk and it also is not outputted: I have tried searching and asking AI and not getting a solution. What is the best way to output this? Thanks ahead of time for any help. |
Replies: 1 comment 1 reply
|
I can see how this was surprising behaviour. I had to poke the base blog myself to figure out what was going on. It is not occuring in other Eleventy projects (that is: you have to configure it to use bundling to observe this). is bundling all <script eleventy:ignore type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebSite",
"name": "{{ metadata.title }}",
"url": "{{ metadata.url }}"
}
</script> |
I can see how this was surprising behaviour. I had to poke the base blog myself to figure out what was going on. It is not occuring in other Eleventy projects (that is: you have to configure it to use bundling to observe this).
https://github.com/11ty/eleventy-base-blog/blob/d84d3fb36419581448f0ba69474b897e5b3bedc4/eleventy.config.js#L47-L53
is bundling all
<script>elements. You can use the escape hatch by addingeleventy:ignoreto make it show up where you placed it: