1
votes

I'm looking at how Blade implements the @section, but it works a little different than I'm used to with Twig. It seems that you can't nest @sections in each other.

Example:

_layout.blade.php (basic layout file)

<html>

    //favicons
    //meta content
    //other basic shizzle

    <head>
        <title>overal</title>
    </head>

    <body>
        @yield('body_content')
    </body>

</html>

website.blade.php (specific implementation)

@extend('_layout.blade.php')

@section('body_content')

    <div class="">
        website-header
    </div>

    <div class="main">

        @section('navigation')
            <nav>website navigation</nav>
        @endsection

        <div class="website">

            {-- the actual content --}
            @yield('content')

        </div>

    </div>

@endsection

blog.blade.php (implementation for the blog-page)

@extend('website.blade.php')

@section('content')
    blog-items
@endsection

faq.blade.php (implementation for the faq-page)

@extend('website.blade.php')

{{-- we don't want the navigation here or want something different --}}
@section('nav')@endsection

@section('content')
    faq-items
@endsection

And I can't solve it with @includes, since I want the flexibility to be able to determine sub-sub sections in sub-views and overwrite their content.

1
You can pass variables from views to views by using @extend('website.blade.php', ['nav' => false]), you could then query this variable in your website.blade.php and remove the nav (for this specific instance, this might give you some place to extend from) - milo526
Well, I don't want to cluther my base templates (or how deep it might go) with variables in case a child needs an overwrite / something else. But it is possible... so my question is not relevant anymore. I did post this below, in case someone might look for the same :) - Oskar

1 Answers

2
votes

Never mind, this is possible It was my editor (PhpStorm) that was bugging me. You CAN nest @section in each other and overwrite/redefine them in extended templates ^^

W00000t