Jonh Doe Jonh Doe - 2 months ago 13
PHP Question

Laravel Blade @include after @section

Why does Blade includes goes before sections in the rendered output the tested code shown below? Is there a way to put after or the middle of sections?

// Specify the filename of the layout (without extension)
@extends('layout')

// The rest of the code of the view template
// Opening content section
@section('content')
// The content that will be injected in the layout replacing “@yield(‘content’)”
This is the home pagevvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
// Closing content section
@stop


@section('content')
<p>This is just Content</p>
@stop

@section('moreContent')
<p>This is More Content</p>
@stop

@section('evenMoreContent')
<p>This is Even More Content</p>
@stop

@include('navigation')

Answer

No, I see no way to do that, and as you are extending a template the only thing that is being rendered is the layout with the sections you define.

If you want to change the order in the output, the layout file is where you can do this.

You should edit the extended template. You can add another section in the template file (@yield('naveigation')) and the define the navigation section later.

In this file:

@section('navigation')
  @include('navigation')
@stop

And in layout.blade.php

Layout
<br>
Nav:
<br>
@yield('navigation')
<br>
Content:
<br>
@yield('content')
Comments