netflex/breadcrumbs

Utilities to create breadcrumb navigation in Netflex.

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

This package is auto-updated.

Last update: 2024-12-17 12:28:31 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.

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>