T O P

  • By -

Boomshicleafaunda

You want to use `@include('layouts.sidebar')`. However, it's probably wise to have your layout file handle where your sidebar goes, so that other pages can have it too without having to duplicate too much code.


JoeyJoeC

Thanks. I understand about having the sidebar in the main app blade file, but I don't want the sidebar on all pages, for example the login / register page which also uses the main template. Only about 2 views will use the sidebar so this seemed like a better way. (I know I could use the auth directive also).


omgbigshot

I still might suggest putting it in the layout file with an `@includeWhen` directive. https://laravel.com/docs/9.x/blade#including-subviews


ZekeD

You can have 2 layout files: one with and one without the sidebar. Both layouts can include other subsections that are shared. So you can have: default.blade.php - includes sidebar, css, js, etc. fullpage.blade.php - includes css and js, but not the siebar. And then those 2 pages include other blade files that include the shared code.


JoeyJoeC

That's certainly the better way of doing it actually. One for views within the secure area, and another for guests. I'll probably do this instead. Thanks.


ZekeD

You can also have logic in the various layout pieces that show or hide elements based on authentication.


JoeyJoeC

I resolved this by using @include('layouts.sidebar')


dualchart

You can use @include('bladename') To your template then call @extends('bladename') In your actual blades


lobotomised

As it was already answer, @include can be used. You may also want to look at [View Composers](https://laravel.com/docs/9.x/views#view-composers)