Skip to content

Instantly share code, notes, and snippets.

@un1ko85
Created November 5, 2015 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save un1ko85/6c8f649c97f9dd942034 to your computer and use it in GitHub Desktop.
Save un1ko85/6c8f649c97f9dd942034 to your computer and use it in GitHub Desktop.
<?php
return function ($bh) {
$bh->match('breadcrumbs', function ($ctx, $json) {
if (!$ctx->param('data')) {
return;
}
foreach ($json->data as $item) {
$mod = isset($item['active']) ? true : false;
if (isset($item['url'])) {
$content[] =[
[
'elem' => 'item',
'tag' => 'li',
'attrs' => ['itemprop' => 'itemListElement', 'itemscope' => true, 'itemtype' => 'http://schema.org/ListItem'],
'content' => [
[
'block' => 'link',
'url' => $item['url'],
'mods' => [ 'theme' => 'vr', 'active' => $mod ],
'attrs' => [ 'itemprop' => 'item'],
'content' => [
[
'elem' => 'name',
'tag' => 'span',
'attrs' => [ 'itemprop' => 'name'],
'content' => $item['name']
],
[
'block' => 'icon',
'mods' => ['font' => true, 'type' => 'angle-right'],
],
],
]
]
]
];
} else {
$content[] = [
'elem' => 'title',
'tag' => 'span',
'content' => isset($item['name']) ? $item['name'] : null,
];
}
}
$ctx->attrs(['itemscope' => true, 'itemtype' => 'http://schema.org/BreadcrumbList'])
->tag('ul')
->content($content);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment