What's your biggest current challenge? Have your say in Community Polls along the right column.

Re: Schema Markup - Can I make section values globally available?

Solved

Schema Markup - Can I make section values globally available?

Jim_Borchardt
Excursionist
14 1 2

Hello, 

I am writing Schema markup for various pages on my website, a lot of which are built using sections.

According to Shopify documentation, I understand that variables within a section are not accessible beyond that section. I also understand that those variables do become dynamically accessible to snippets rendered within the same section block.

I am looking for a work around. Is there any possible way to pull dynamic values from a section block to place into a snippet? 

I have created a snippet that contains JSON LD schema markup and am hoping I can find a way to pull dynamic values from various section blocks into this snippet. If this was possible, my Schema markup could be nested, making it easy for search engines to understand. 

As it is now, I have to render each pertinent schema snippet into the section block in order for the dynamic values to be available. The output of this is several different schema markups for one page, which makes it more difficult for search engines to understand the focus of the page. If I could only render a schema snippet singularly per page, it would make my page much more understandable. I realize this is easily possible of the text is static. But that's not why I'm here!

How can I make dynamic values from sections available to an overarching snippet? 

Accepted Solution (1)

tim
Shopify Partner
3911 394 1435

This is an accepted solution.

Basically, all variables inside section are scoped to this section.

So you can't define variable in one section and use it in another.

Section blocks, however, are not scoped, so whatever you define in a section block will be visible throughout entire section in all blocks.

 

Snippets, when they are rendered (rather then included) are also scoped and see no variables from parent snippet/section/template. Unless you pass them as snippet parameters explicitly.

 

The entire idea behind scoping is to render sections and snippets independently in parallel to improve rendering speed.

 

If you include a snippet in a section, it will have access to all variables defined in this section.

 

As to your concern -- it's fine to have multiple JSON-LD occurrences on the same page, you'd just need to link them together by using @context and @Id :

See https://github.com/Shopify/dawn/pull/3380#issuecomment-2074894230 and https://www.w3.org/TR/json-ld/#advanced-context-usage.

 

 

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com

View solution in original post

Replies 6 (6)

magecomp
Shopify Partner
450 31 47

Hello @Jim_Borchardt 


Why don't you use this simple FREE SEO shopify app for schema related requirements

https://apps.shopify.com/spider-website-seo-optimizer

Helping voluntarily. Please like and accept the solution if it helps. Thanks!
Our Bestseller Shopify Apps    |      Mobile App Builder by MageComp    |      Shoplock Hide Pages/Collections

Need a developer?  Just visit MageComp website

tim
Shopify Partner
3911 394 1435

This is an accepted solution.

Basically, all variables inside section are scoped to this section.

So you can't define variable in one section and use it in another.

Section blocks, however, are not scoped, so whatever you define in a section block will be visible throughout entire section in all blocks.

 

Snippets, when they are rendered (rather then included) are also scoped and see no variables from parent snippet/section/template. Unless you pass them as snippet parameters explicitly.

 

The entire idea behind scoping is to render sections and snippets independently in parallel to improve rendering speed.

 

If you include a snippet in a section, it will have access to all variables defined in this section.

 

As to your concern -- it's fine to have multiple JSON-LD occurrences on the same page, you'd just need to link them together by using @context and @Id :

See https://github.com/Shopify/dawn/pull/3380#issuecomment-2074894230 and https://www.w3.org/TR/json-ld/#advanced-context-usage.

 

 

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com
Jim_Borchardt
Excursionist
14 1 2

Hey Tim, thanks so much for your reply. It was very helpful. Never thought about it from the angle mentioned in your last sentence. That is how I will execute. 

Jim_Borchardt
Excursionist
14 1 2

Hey Tim, quick question. I'm hung up a bit on the particulars:

Does the @Id value used across the various schemas need to be of the exact same value?

This: 
@type CollectionPage 

@Id /collections/jacket

 

@type ImageObject 

@Id /collections/jacket 

Or this: 

@type CollectionPage 

@Id /collections/jacket#CollectionPage

 

@type ImageObject 

@Id /collections/jacket#JacketGallery

tim
Shopify Partner
3911 394 1435

You can have multiple objects represented on the same page. Say, you can have your company object, product object, recipe, articles...

If you have several occurrences for, say @type Product, they will be recognised as multiple products, each missing some data.

That's why you need to use the same @Id to tell the parsers to combine both jsons into single object.

 

So, if we're talking about collection page and image is the collection image, I'd be leaning toward the first of your codes. As in the github link above.


Finally, you can always feed your data to a testing tool https://developers.google.com/search/docs/appearance/structured-data to see what results it will produce.

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com
Jim_Borchardt
Excursionist
14 1 2

Thanks Tim. Yes, I have different objects in each snippet. For example. I have a collection page that contains a collection, an image with text section, a gallery, and lastly a video. 

I have created Schema markup for the collection page, and for all the subsections. Each section is assigned its own object. Thus my question regarding @Id. Each section has a standalone purpose, but is related to every other section. Priority overall is to ensure that search engines recognize that each markup contribute to the collection page as a whole. 

Sounds like I can get away with using the main url as the @Id followed by a tag particular to the section