floor12/breadcrumbs-microdata

Html breadcrumb with microdata generator.

1.0.0 2021-05-04 13:57 UTC

This package is auto-updated.

Last update: 2024-04-27 13:20:42 UTC


README

Scrutinizer Code Quality Build Status Code Coverage

Installation

Add this package to your project with composer.

composer require "floor12/breadcrumbs-microdata"

Usage

The breadcrumbs api is simple and clear. Here are some examples. This:

use floor12\Breadcrumbs\Breadcrumbs;

$elements = [
    '/first' => 'First element 1',
    '/first/second' => 'Second element 2',
    'Current',
]; 
(new Breadcrumbs($elements))->getHtml();

or this:

use floor12\Breadcrumbs\Breadcrumbs;

(new Breadcrumbs())
        ->addElement('First element 1', '/first')
        ->addElement('Second element 2', '/first/second')
        ->addElement('Current')
        ->getHtml();

... will generate this html code:

<ol itemscope itemtype="http://schema.org/BreadcrumbList" class="f12-breadcrumbs" id="f12-breadcrumbs">
    <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
        <a data-pjax="0" itemprop="item" href="/first">
            <span itemprop="name">First element 1</span>
            <meta itemprop="position" content="1">
        </a>
    </li>
    <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
        <a data-pjax="0" itemprop="item" href="/first/second"><span itemprop="name">Second element 2</span>
            <meta itemprop="position" content="2">
        </a>
    </li>
    <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
        <span itemprop="name">Current</span>
        <meta itemprop="position" content="3">
    </li>
</ol>

Its also possible to set your own id and CSS class name:

use floor12\Breadcrumbs\Breadcrumbs;

(new Breadcrumbs([]))
    ->setMainId('some-id')
    ->setCssClass('some-css-class')
    ->getHtml();

Css styles

To make default pretty styled breadcrumbs, include scss/f12-breadcrumbs.scss or scss/f12-breadcrumbs.css to your project styles and override what you need.

Contributing

I will be glad of any help in the development, support and bug reporting of this module.