jinnguyen/puja-breadcrumb

Puja-Breadcrumb is a simple class to manage the breadcrumbs

v1.0.0 2017-01-08 12:47 UTC

This package is not auto-updated.

Last update: 2024-04-22 12:34:46 UTC


README

Puja-Breadcrumb is a simple class to manage the breadcrumbs

Installation

Just run this on the command line:

composer require jinnguyen/puja-breadcrumb

Usage

include '/path/to/vendor/autoload.php';
use Puja\Breadcrumb\Breadcrumb;

Examples:

Simple

$breadcrumb = new Breadcrumb;
$breadcrumb->add('Subpage 2', '/subpage2');
echo $breadcrumb->render();

new breadcrumb with a array

$breadcrumb = new Breadcrumb(array(
    array('title' => 'Home', 'link' => '/'),
    array('title' => 'Page', 'link' => '/page'),
    array('title' => 'Subpage', 'link' => '/subpage/?a=5&b[]=7&b[]=8'),
));
$breadcrumb->add('Subpage 2', '/subpage2');
echo $breadcrumb->render();

The rest of the documentation will assume you have a $breadcrumb instance on which you are making calls.

Adding a crumb

$breadcrumb->add('Home', '/');

Delete all crumb

$breadcrumb->deleteAll();

Delete last crumb

$breadcrumb->deleteLastItem();

Count breadcrumb elements

$breadcrumb->count();

Check empty

$breadcrumb->isEmpty(); // same with $breadcrumb->count() == 0

Get data:

$breadcrumb->getData(); // get all breadcrumb nodes

First and Last CSS classes

    
  • Home // First Breadcrumb element
  • Page
  • Subpage
  • Subpage 2 // Last Breadcrumb Element

The first/last css classes are the class of first/last Breadcrumb element

$breadcrumb->setFirstCssClassName($className);
$breadcrumb->setLastCssClassName($className);

The Element

The default breadcrumb element is <li class="{FirstLastCss}">%s{Divider}</li>. To change it, use the setElement method like so:

$breadcrumb->setElement('<span class="{FirstLastCss}">%s{Divider}</span>');

Note:

"%s" is required for Breadcrumb::$element
{FirstLastCss}: will be replaced by Breadcrumb::$firstCssClassName for first element and Breadcrumb::$lastCssClassName for last element
{Divider}: will be replaced by Breadcrumb::$divider

The List Element

The default list element used to wrap the breadcrumbs, is <ul>%s</ul>. To change it, use the setListElement method like so:

$breadcrumbs->setListElement('<ol class="ol-breadcrumb">%s</ol>');

Note:

"%s" is required for Breadcrumb::$listElement

Divider

The default breadcrumb divider is `` (empty). This will be replace to placeholder {Divider} in property Breadcrumb::$element. If you'd like to change it to, for example, /, you can just do:

$breadcrumb->setDivider('/');

Output

Finally, when you actually want to display your breadcrumbs, all you need to do is call the render() method on the instance:

echo $breadcrumb->render();

Note that by default crumb titles are rendered with escaping HTML characters, if you'd like to ignore it just do like so:

$breadcrumb->setSafeHtml(false);