Breadcrumbs
Breadcrumbs in general are automated. However they can be modified, disabled, and managed manually too.
Basic Usage
To add manage breadcrumbs for your own module you must first include the \Anomaly\Streams\Platform\Ui\Breadcrumb\BreadcrumbCollection
class.
BreadcrumbCollection::add()
The add
method adds a breadcrumb to the end of the collection.
Returns: \Anomaly\Streams\Platform\Ui\Breadcrumb\BreadcrumbCollection
Arguments
Key | Required | Type | Default | Description |
---|---|---|---|---|
$key |
true |
string |
none |
The breadcrumb key name. Translation keys are supported. |
$url |
true |
string |
none |
The URL or path for the breadcrumb. |
Example
$breadcrumbs->add('anomaly.module.products::breadcrumb.products', '/products');
**Note:** Breadcrumbs are available as a property in controllers by default.
<?php namespace Anomaly\ProductsModule\Http\Controller;
use Anomaly\ProductsModule\Category\Contract\CategoryRepositoryInterface;
use Anomaly\Streams\Platform\Http\Controller\PublicController;
class CategoriesController extends PublicController
{
/**
* View products within a category.
*
* @param CategoryRepositoryInterface $categories
* @return \Illuminate\Contracts\View\View
*/
public function view(CategoryRepositoryInterface $categories)
{
$category = $categories->findByPath($this->route->getParameter('path'));
$this->breadcrumbs->add(
'module::breadcrumb.products',
$url->route('anomaly.module.products::products.index')
);
$this->breadcrumbs->add($category->getName(), $this->url->make('anomaly.module.products::category', $category));
return $this->view->make('anomaly.module.products::categories/view');
}
}
Displaying Breadcrumbs
The breadcrumb collection is loaded into the template
super variable letting you display breadcrumbs as needed.
<ol class="breadcrumb">
{% for key, url in template.breadcrumbs %}
{% if loop.last %}
<li class="active">{{ trans(key) }}</li>
{% else %}
<li><a href="{{ url }}">{{ trans(key) }}</a></li>
{% endif %}
{% endfor %}
</ol>