Override section in a caravan blade template throwing variables undefined

I am using Laravel 4 and blade templates and am encountering a problem when trying to extend the template.

In my layout I have

@yield('content')

and on my page I have

@section('content')
    Welcome {{ $name }}
@stop

which works fine, I created another page, very similar to my first one, and just want to change the override admin content section. The other sections in the template are beautiful.

so I am expanding my page and doing

@section('content')
    Hello!
@stop

I get an undefined notification with the variable $ name.

I tried

@section('content')
    Hello!
@overwrite

and the same deal, I get an error message. I checked my controller and it uses the correct template. I do not call @parent, so I do not understand how I can overwrite a section in a template without notification errors?

+3
4

Blade , . , , , . , , .

, , , - , , , .

- , . , .

View::composer(array('pages.admin'), function($view)
{
    $view->with('name', Auth::user()->username);
});

. , , . , , .

View::creator(array('pages.admin'), function($view)
{
    $view->with('name', Auth::user()->username);
});

. ( Laravel 5.)

+8

, , , Laravel . :

//testlayout.blade.php:

    <html>
    <body>
        @yield('sidebar', 'This is the master sidebar. {{ $name }}' )

        <div class="container">
            @yield('content')
        </div>
    </body>
   </html>

: views/test.blade.php

@extends('layouts.testlayout')


@section('sidebar')
   No variable in the child
@stop

@section('content')
    This is a child content
@stop

$name, . , ,

+1

Laravel 4, , , Laravel 5.5 (, , - ), , , @extend ing.

. :

@extend('my.parent.view', ['name' => ''])

, , .

. $parent, $child, , , :

@extend('my.parent.view', ['parent' => $child->parent])
0

:)

@ / . (/), PHP .

, /.

!

-3

All Articles