I’ll follow some tutorials about Laravel 3, and know, I have a problem, with one:
@section('post_navigation')
@if(Auth::check())
@include('plugins.loggedin_postnav')
@endif
@endsection
Why this section not appear?
I try remove all content in section, for example;
@section('post_navigation')
<h1>Test</h1>
@endsection
But doesn’t work.
The complete code is that:
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
{{ HTML::link('/', 'Instapics', array('class' => 'brand')); }}
<div class="nav-collapse">
<ul class="nav">
@section('navigation')
<li class="active">{{ HTML::link('/', 'Home') }}</li>
@yield_section
</ul>
</div>
@section('post_navigation')
@if(Auth::check())
@include('plugins.loggedin_postnav')
@endif
@endsection
</div>
</div>
</div>
[EDIT]
I change @endsection to @yield_section, and works, BUT, I still not understand, for example (in User_Controller index view):
@section('post_navigation')
@parent
@endsection
Why not appear the include?
Why I need change endsection to yield_section?
When you use @section, you define a section like defining a variable. Then, you can use it where you want by
@yield('sectionname')(or by using another way I specified in the second paragraph). For example, you can look at this:@section / @endsection and @section / @yield_section are not same. @section / @yield_section defines a section area, not a section. In other words, it calls a variable. Actually it is more similar to yield(‘sectionname’) than @section / @endsection. It has default value as a main difference from yield.
You can define an area which has default value, and then you can change it by defining a section. This logic mostly used while creating and using layouts. For example, Let below page be our main (main.blade.php) layout.
Generally layouts are not used directly. Another page is created and specified in the page its layout like
@layout('main'). Then, sections are defined and laravel templating system change the defined section. Let this page be our post (post.blade.php) page:When we return post view
View::make('profile');, as you can see, layout logic will work and sections in main.blade.php will be changed with we defined in this page. So, the output will be:By the way,
@parentreturns default value in section area and@includeis same logic with include in php.Have a nice day.