Reputation:
In my site I have seven different HTML Layouts. The reason i ended up having so many is because some pages had different headers/footers and some pages did not pass data from the back end which was required for the layout to work. I've ended up with several layouts. This is a pretty big inconvenience. Is there any way around this?
Upvotes: 0
Views: 448
Reputation: 344
I think i have found a better way around to achieve ( different headers and footers for different pages in laravel ).
views/
├── frontend/
│ ├── index.blade.php
| |
│ ├── layouts/
| | ├── app.blade.php
| | |
| ├── includes/
| | ├── nav.blade.php
| | |
| | ├── headers/
| | | ├── main-header.blade.php
| | | ├── another-header.blade.php
| | ├── footers/
| | | ├── main-footer.blade.php
| | | ├── another-footer.blade.php
Now in app.blade.php we use the @Yield('')
<body id="body">
@include('includes.partials.read-only')
@yield('header')
<div id="app">
<div class="container">
@include('includes.partials.messages')
@yield('content')
</div><!-- container -->
</div><!-- #app -->
@yield('footer')
And in index.blade.php i want to add the footer another-footer.blade.php
@section('footer')
@include('frontend.includes.footers.another-footer.blade.php')
@endsection
In another pages if i want to use another footer then we can just change the included file inside the footer section.
Upvotes: 0
Reputation: 51
another big hidden gem of blade I found was the @stack
and @push
functions.
You can use @push
to add sections to a certain stack
In your template
@stack('scripts')
And then in your views
@push('script')
<!-- Here goes your normal HTML -->
@endpush
Upvotes: 1
Reputation: 1
For the layouts that require data, I think you could make it optional in the template and validate the data requirement in the controller instead of the template
Upvotes: 0