Can blade yield to a section in the same file?
Asked Answered
K

1

7

I have file master.blade.php, which contains @yield('mainsection'). Then I have another file, with:

@extends('layouts.master')

@section('mainection')
    test1
    @yield('othersection')
@stop

@section('othersection')
    test2
@stop

I can see test1, but not test2 - from which I conclude that blade does not allow you to yield to a section defined in the same file. Is there any way to work around that? Or will I have to add a third file between these two, to contain the mainsection and yield to othersection?

Knitted answered 13/2, 2014 at 14:15 Comment(0)
M
13

it can be shown, but @section must be written before @yield

@extends('layouts.master')

@section('othersection')
  test2
@stop

@section('mainection')
  test1
  @yield('othersection')
@stop
Meath answered 6/9, 2015 at 19:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.