Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel blade templating yield not working

I have a layouts/app.blade.php view where I yield a content section.

layouts/app.blade.php

@yield('content')

adminpanel/adminpanel.blade.php

@extends('layouts.app')

@section('content')
    <div id="wrapper">
        <div id="sidebar-wrapper">
            @yield('sidebar')
        </div>

        <div id="page-content-wrapper">
            <div class="container-fluid">
                @yield('page-content')
            </div>
        </div>
    </div>
@endsection

adminpanel/sidebar.blade.php

@extends('adminpanel.adminpanel')

@section('sidebar')
    <ul class="sidebar-nav">
        <li class="sidebar-brand">
            <a href="#">
                Profile
            </a>
        </li>
        <li>
            <a href="#">Dashboard</a>
        </li>
        <li>
            <a href="#">News</a>
        </li>
    </ul>
@endsection

Am I doing something wrong here?

When I type something in the adminpanel/adminpanel.blade.php view it works but the yielding of partials doesn't work.

like image 492
user3652775 Avatar asked Dec 14 '17 09:12

user3652775


1 Answers

If you are returning the "adminpanel/adminpanel", then you must include the sidebar from the admin-panel, not "yield" something for what you don't have the contents.

@include('adminpanel.sidebar') 

instead of

@yield('page-content')

and then in your sidebar, remove all blade directives because they are no longer needed.

<ul class="sidebar-nav">
    <li class="sidebar-brand">
        <a href="#">
            Profile
        </a>
    </li>
    <li>
        <a href="#">Dashboard</a>
    </li>
    <li>
        <a href="#">News</a>
    </li>
</ul>
like image 138
Amarnasan Avatar answered Sep 28 '22 23:09

Amarnasan