Reputation: 2262
I'm using custom error views with blade files located in resources/views/errors
. My error views are made from the same template view than the normal pages so they extend my frontoffice
layout. Here is the hierarchical scheme of my templates.
app.blade.php
layout.frontoffice.blade.php
someFrontOfficePage.blade.php
404.blade.php
The navbar component is included in layout.frontoffice.blade.php
so I can't access it from 404.blade.php
. Just to be clear, the navbar is a component as described here and is thus in yet another file.
The problem: I want to hide the links in the navbar but not the navbar itself when in an error view (such as 404.blade.php
). The idea was to check if the status code is different from 200 inside my navbar component but I don't know how to access the response from a blade file.
I'd prefer to do it this way instead of copy-pasting my navbar inside a new error template to avoid redundancy.
Upvotes: 3
Views: 1819
Reputation: 412
well i had the same issue once, the solution is simple, in the error 404 blade you use extends('layouts.frontoffice')
right ? then you can pass a variable to this extension, extends('layouts.frontoffice', ['code' => 404])
and in your navbar component :
@if(isset($code) && $code == 404)
//do something
@else
//do something else
@endif
Upvotes: 2