dimanche 17 juin 2018

Why do laravel blade templates have both @yield and @extend directives?

I don't understand why there are two complementary, but also possibly contradictory directives with Laraval templates. When building views, is it just a matter of being robust, or does it create more options, or is it something else?

From the official documentation, a container defines @sections and "pulls" in content from other view fragments by means of @yield statements... right?

<!-- Stored in resources/views/layouts/app.blade.php -->

<html>
    <head>
        <title>App Name - @yield('title')</title>
    </head>
    <body>
        @section('sidebar')
            This is the master sidebar.
        @show

        <div class="container">
            @yield('content')
        </div>
    </body>
</html>

And then the child component is used by saying "wrap me" in a master layout, by means of the @extends statement.

<!-- Stored in resources/views/child.blade.php -->
@extends('layouts.app')
@section('title', 'Page Title')

Surely this increases the risk of them sometimes contradicting each other?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire