1

I have the following structure:

- master.blade {

@yield('menu') // here I load the one and only menu I have

@yield('content') // here I load different pages

}

- menu.blade {
@extends('master')

@section('menu')
main menu
@stop
}

- other pages using the same format {
@extends('master')

@section('content')
here is the content
@stop
}

For some reason the menu is not loaded. Any ideas why? I try to load the menu and then page. It's simple stuff, but for some reason I don't see why it's not working.

1
  • if you're happy with my answer below, accept it :) Commented Mar 20, 2015 at 13:07

2 Answers 2

2
  1. use @include('menu') instead of @yield('menu') in master.blade layout.

  2. remove @extends, @section('menu') and @stop from menu.blade

After these changes your code should look like:

master.blade

@include('menu')

@yield('content')

menu.blade

main menu

other pages

@extends('master')

@section('content')
    here is the content
@stop

Read more about templates: http://laravel.com/docs/5.0/templates

btw, you can use @endsection instead of @stop, it's more readable as to me.

Sign up to request clarification or add additional context in comments.

Comments

1

The flow should be like this:

- master.blade {

@include('menu') // here I load the one and only menu I have

@yield('content') // here I load different pages

}

- menu.blade {

   Markup for the main menu

}

- other pages using the same format {
@extends('master')

@section('content')
   here is the content
@stop
}

Create simple menu file and include it in master template, yield is used for dynamic contents.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.