Schema Markup: How to temporarily “escape” itemscope

谁都会走 提交于 2019-12-25 03:08:05

问题


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, not http://schema.org/medicalClinic)
  • you were missing an itemprop’s closing "


来源:https://stackoverflow.com/questions/32952794/schema-markup-how-to-temporarily-escape-itemscope

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!