netflex/breadcrumbs

Utilities to create breadcrumb navigation in Netflex.

v5.0.0 2023-08-25 10:39 UTC

This package is auto-updated.

Last update: 2024-04-19 12:31:45 UTC


README

Stable version Build status License: MIT Contributors Downloads

[READ ONLY] Subtree split of the Netflex Breadcrumbs component (see netflex/framework)

Utilitiy class for creating breadcrumb navigations in Netflex Pages.

Table of Contents

Installation

composer require netflex/breadcrumbs

Usage

use Netflex\Breadcrumbs\Breadcrumb;
use Netflex\Pages\Page;

// Create breadcrumb based on current page
$page = Page::current();
$options = [];
$breadcrumb = new Breadcrumb($page, $options);

// Get breadcrumb data
$breadcrumb = $breadcrumb->get();

The returned breadcrumb data will be formatted like this:

Illuminate\Support\Collection Object ( 
  [items:protected] => Array ( 
    [0] => Array ( 
      [label] => 'Home'
      [originalLabel] => 'Home'
      [path] => '/'
      [id] => 10000 
      [type] => 'page'
      [published] => true 
      [current] => false
    ) 
    [1] => Array ( 
      [label] => 'Example' 
      [originalLabel] => 'Example' 
      [path] => '/example' 
      [id] => 10027 
      [type] => 'page' 
      [published] => true 
      [current] => true
    )
  )
)

Options

Options can be passed as an array when you instantiate the class.

Option Type Default value Description
hideCurrentPage boolean false If set to true the current page will be omitted from the breadcrumb
hideRootPage boolean false If set to true the root page will be omitted from the breadcrumb
overrideRootPageLabel string|null null If provided with a string, it will override the label of the root page
overrideRootPagePath string|null null If provided with a string, it will override the path of the root page
inferCurrentPage boolean true If set to false the current page will not be marked as current in the breadcrumb. Useful when appending items manually.

Example usage in Blade components

<nav class="Breadcrumb" aria-label="Breadcrumb">
  <ol class="Breadcrumb__list">
    @foreach ($breadcrumb as $item)
      @if ($item['current'])
        <li class="Breadcrumb__item Breadcrumb__item--active">
          <a class="Breadcrumb__link" href="{{ $item['path'] }}" aria-current="page">
            {{ $item['label'] }}
          </a>
        </li>
      @else
        <li class="Breadcrumb__item">
          <a class="Breadcrumb__link" href="{{ $item['path'] }}">
            {{ $item['label'] }}
          </a>
        </li>
      @endif
    @endforeach
  </ol>
</nav>