Skip to content

Instantly share code, notes, and snippets.

@thejimbirch
Created April 13, 2020 13:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thejimbirch/18f4dc351c2eb3f205e906afc95ed135 to your computer and use it in GitHub Desktop.
Save thejimbirch/18f4dc351c2eb3f205e906afc95ed135 to your computer and use it in GitHub Desktop.
Add Schema.org BreadcrumbList inline in Drupal 8+ in your theme's templates.
{#
/**
* @file
* Theme override for a breadcrumb trail.
*
* Available variables:
* - breadcrumb: Breadcrumb trail items.
*/
#}
{% if breadcrumb %}
<ol itemscope itemtype="http://schema.org/BreadcrumbList" class="breadcrumbs" aria-label="breadcrumb">
{% for item in breadcrumb %}
<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
{% if item.url %}
<a itemprop="item" href="{{ item.url }}">
<span itemprop="name">{{ item.text }}</span>
<meta itemprop="position" content="{{ loop.index }}" />
</a>
{% else %}
<span itemprop="item">
<span itemscope itemprop="identifier" itemtype="http://schema.org/PropertyValue" hidden>
<meta itemprop="url">{{ url('<current>') }}</span>
</span>
<span itemprop="name">{{ item.text }}</span>
<meta itemprop="position" content="{{ loop.index }}" />
</span>
{% endif %}
</li>
{% endfor %}
</ol>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment