问题
I would like to markup some content using Schema but am running into an issue with my itemscopes.
I have the following markup right now:
<div itemscope itemtype="https://schema.org/medicalClinic">
<div itemprop="availableService" itemscope itemtype="https://schema.org/MedicalProcedure">
<span itemprop="name">First Service Name</span>
<span itemprop="description">First Service Description</span>
<div itemprop="availableService itemscope itemtype="https://schema.org/MedicalProcedure">
<span itemprop="name">Second Service Name</span>
<span itemprop="description">Second Service Description</span>
</div><!-- end second service -->
<span itemprop="followup">First Service Followup</span>
</div><!-- end first service -->
</div><!-- end MedicalClinic schema -->
Due to the way the content is structured, a second service appears in the middle of the container for the first service. Itemprops for the first service appear before and after the second service.
Google's structured data testing tool shows an error stating that an availableService is not a property of an availableService (obviously not what I would want anyway).
My question is how do I "escape" the scope of my first service so I am able to markup my second service, and then re-enter the first service's scope?
回答1:
There’s an ugly solution for this which involves adding a div
with an itemscope
(without itemtype
) and itemref
+id
:
<div itemscope itemtype="http://schema.org/MedicalClinic" itemref="second-service">
<div itemprop="availableService" itemscope itemtype="http://schema.org/MedicalProcedure">
<span itemprop="name">First Service Name</span>
<span itemprop="description">First Service Description</span>
<div itemscope>
<div itemprop="availableService" itemscope itemtype="http://schema.org/MedicalProcedure" id="second-service">
<span itemprop="name">Second Service Name</span>
<span itemprop="description">Second Service Description</span>
</div><!-- end second service -->
</div> <!-- end dummy div -->
<span itemprop="followup">First Service Followup</span>
</div><!-- end first service -->
</div><!-- end MedicalClinic schema -->
Notes about your markup:
- you may want to use HTTP instead of HTTPS Schema.org URIs
- Schema.org URIs are case-sensitive (e.g., it’s
http://schema.org/MedicalClinic
, nothttp://schema.org/medicalClinic
) - you were missing an
itemprop
’s closing"
来源:https://stackoverflow.com/questions/32952794/schema-markup-how-to-temporarily-escape-itemscope