Support the ongoing development of Laravel.io →
posted 10 years ago
Blade
Last updated 2 years ago.
0

Using just @yield() you wont be able to have a default content.

Using @section()..@show you'll be able to have a default content and you can do stuff like

<title>
@section('title')
Laravel
@show
</title>

Then on one of your views you can do the following

@section('title')
@_parent (remove the _, the forum removes the whole call for some weird reason)
:: Some page
@stop

Which will result on

<title>
Laravel :: Some Page
</title>

Notice the @_parent you can position it before or after the content and it will inherit your default content, if you don't use @_parent the default will be completely replaced.

Hope it helps.

Last updated 2 years ago.
0

@yield('some_section') actually creates a section in master layout.

<!DOCTYPE html>
<html lang='en'>
    <head>
        <meta name='viewport' content='width=device-width, initial-scale=1'>
        <title>@yield('title') | User Admin</title>
        <link rel='stylesheet' href=bootstrap.min.css'>
    </head>
    <body>
        <div class='container-fluid'>
            <div class='row'>
                @yield('content')
            </div>
        </div>
    </body>
</html>

@section('some_section') makes it work in general template, which extends master @extends('master_layout')

@extends('layouts.master')
 
@section('title')

 Login

 @stop

 
@section('content')
 
<div>
 content
</div>
 
@stop

This way u have full control over your html output.

Last updated 2 years ago.
0

brunogaspar said:

Using just @yield() you wont be able to have a default content.

Using @section()..@show you'll be able to have a default content and you can do stuff like

<title>
@section('title')
Laravel
@show
</title>

Then on one of your views you can do the following

@section('title')
@_parent (remove the _, the forum removes the whole call for some weird reason)
:: Some page
@stop

Which will result on

<title>
Laravel :: Some Page
</title>

Notice the @_parent you can position it before or after the content and it will inherit your default content, if you don't use @_parent the default will be completely replaced.

Hope it helps.

With @yield i am able to have default content:

@yield('section', 'default value')

I have figured out myself:

show is used in case if you need to use parent and append content to a parent.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.