Mahdi.Pishguy Mahdi.Pishguy - 8 months ago 86
PHP Question

Laravel use yield for separated layouts on different folder

in

resources
folder and
layouts/backend/
and i have
main.blade.php
file as master template and
partials
folder which that have some files such as
sidebar
,
footer
and etc, for example:

/layouts/backend/main.blade.php:

<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>Laravel</title>
</head>
<body>
<!-- Footer -->
@yield('partials.footer')
<!-- /footer -->
</body>
</html>


/layouts/backend/partials/footer.blade.php:

@extends('layouts.backend')

@section('footer')
<div class="footer text-muted">Hello</div>
@endsection


after save and refreshing page i don't have
footer
on page

Answer Source

Have a look at the Docs, the section about Blade is really good.

I think there are a few logical issues here. If you have a footer that you want to include in your backend/master template, then there's no need to extend the layout in your footer, simply include it in your master template. Here's an example:

layouts/backend/main.blade.php:

<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Laravel</title>
</head>
<body>
    @yield('main')

    <!-- Footer -->
    @include('layouts.backend.partials.footer')
    <!-- /footer -->
</body>
</html>

layouts/backend/partials/footer.blade.php:

<div class="footer text-muted">Hello</div>

Also, you might want to review your folder organisation, maybe you can go with something similar

views/layouts/backend.blade.php  
views/layouts/frontend.blade.php  
views/layouts/backend/footer.blade.php  
views/layouts/backend/header.blade.php  

This is just an idea, of course you can do the folder organisation as you prefer.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download