ideas icon indicating copy to clipboard operation
ideas copied to clipboard

Can breadcrumbs include 404 errors?

Open stuartcusackie opened this issue 3 years ago • 0 comments

Just a thought, but I think the breadcrumbs tag data should contain an indication of whether the current view is a 404 error, or other error response code. My opinion is that an error view is part of the breadcrumb trail and should be included.

The goal is to produce something like this on 404 error pages, and other error pages if required. image

Current approach

At the moment I am working around by passing additional variables to my breadcrumbs partial on my error templates: @include('partials.breadcrumbs', ['customBreadcrumb' => 'Page Not Found'])

@foreach(\Statamic::tag('nav:breadcrumbs')->fetch() as $item)
        {{ -- Do the breadcrumb logic --}}
@endforeach

@if(isset($customBreadcrumb))
   <span>{{ $customBreadcrumb }}</span>
@endif

Ideal approach

I think it would be better encapsulated if the breadcrumbs indicated that I was on an error page. Example:

@foreach( \Statamic::tag('nav:breadcrumbs')->fetch() as $item)
  @if($item['is_current'] && $item['response_code'] == '404')
   <span>Page Not Found</span>
  @elseif
        {{ -- Do the breadcrumb logic --}}
  @endif
@endforeach

stuartcusackie avatar Jul 07 '22 13:07 stuartcusackie