Closed CovertCode closed 1 year ago
Hi @CovertCode! Where was the example in docs that didn’t work for you?
I think it would be good to have an example of this in docs. Using JSON-LD inside of a <script>
tag is common for SEO purposes and I have seen confusion about this a couple of times in support, mostly because:
1) You can't use JSX / JSON inside a <script>
tag because it expects JavaScript
2) It is not immediately obvious that set:html
would work on a <script>
tag because it expects JavaScript and it has HTML in the name
3) Newer users might not know about set:html
Also the above example could be improved using JSON.stringify
:
<script type="application/ld+json" set:html={JSON.stringify({
"@context": "https://schema.org/",
...
})}/>
Is this worth documenting? Can I make a PR?
Hey @BryceRussell! So, I was curious and I checked to see whether our Directives Reference page (in Reference) showed any examples of set:html
in a script tag specifically... and it doesn't!
So, yes, I'd say let's add an example of this! At the very least, maybe on the Template Directives reference page? Do you have any other idea of where it would be more/most helpful? Either thinking about what someone might be trying to do, or where a reader might think to look when they encounter this problem?
Hey @sarah11918, I agree, the template Template Directives reference page looks like the best place for an example.
The only other section that might be more searchable is the "Common Script Patterns" section, but it might not fit that section very well since it talks about client side patterns.
So I was adding schema markup for my blog post but when I tried to pass data like post url and author name then I was unable to do that. In discord support I got to know about
set:html
but in official docs the mention method of usingset:html
didn't worked.Here's part of schema script:
So to use set:html properly in this case was:
Had to treat whole script tag data under template literal.