Extending a Navigation Menu in Partials in Laravel 5

This post is more of a reminder to myself on how to extend a menu in an included partial when using the PHP framework Laravel.

As of this writing I’m using Laravel 5.1.16.

Hopefully other people find it useful too.

Let’s say you have a similar folder setup to this in your project:

The default.blade.php template includes the navigation partial:

In order to be able to extend the navigation menu from within index.blade.php you need to add @yield(‘nav’) to the nav.blade.php file.

Then from within the index.blade.php file you can extend the navigation menu using the following code:

I’m not 100% sure this is the best way to do it, but I searched for a way to use @parent within the nav.blade.php file and could not find a solution.

Leave a comment if you know of a better way to achieve this.

Leave a Reply

Your email address will not be published. Required fields are marked *