Skip to content

Instantly share code, notes, and snippets.

@vuchkov
Forked from thejimbirch/breadcrumb.html.twig
Created October 7, 2021 13:35
Show Gist options
  • Save vuchkov/2e6c7eeea28a65c7abf383a023fd4def to your computer and use it in GitHub Desktop.
Save vuchkov/2e6c7eeea28a65c7abf383a023fd4def 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