If you look to laravel official documentation http://laravel.com/docs/4.2/templates It says that giving this layout:
<!-- Stored in app/views/layouts/master.blade.php -->
<html>
<body>
@section('sidebar')
This is the master sidebar.
@show
<div class="container">
@yield('content')
</div>
</body>
</html>
Extended by this view
@extends('layouts.master')
@section('sidebar')
<p>This is appended to the master sidebar.</p>
@stop
@section('content')
<p>This is my body content.</p>
@stop
Will append to the section sidebar
. But actually if you try is it doesn't append, it just override the content from the extended template.
I heard about others blade function like @append, @prepend, @parent
... no one seems to work.
Beside, this example in the official doc which doesn't work, I find that the blade documentation is very poor. There's nothing about blade function like @parent
for instance.
as mentioned before, I used
@parent
and it works fine for me. May be an example for extendedtitle
will helps:master.blade.php
includes/head.blade.php
post.blade.php
Therefore, The Title will be rendered to be like this:
Actually, this will render something like:
so you can use the section second parameter to set the values:
includes/head.blade.php
post.blade.php
And this will render:
So you will get rid of the lines inside the title,
Hope that's helps.
Note: This is used for Laravel 5.2, Not quite sure but as I remember, it works for Laravel 4 too.
You can simply use
@append
...See here.
To understand how this works...
The
compileStatements()
method in the BladeCompiler calls the methodcompileAppend()
, as you can see here:In turn, that inserts a call to
appendSection()
which looks like this:The example in the documentation from Larvel website does indeed seem to be flawed, but I think it's a markdown parsing problem on the website, the same docs on github show the correct code:
In any case
@parent
does indeed work. The example in the docs should look like this:A quick look in the
Illuminate/View/Factory.php
confirms what@parent
does: