Zing. compile-to-PHP template engine GitHub ↗

Layout Inheritance

Create a parent layout using @yield to define sections:

{{-- layouts/main.zing --}}
<!DOCTYPE html>
<html>
<head><title>{{ $title }}</title></head>
<body>
    <main>@yield('content')</main>
    @yield('sidebar', '<p>No sidebar</p>')
</body>
</html>

Child templates use @extends to declare their parent and @section to provide content:

{{-- pages/settings.zing --}}
@extends('layouts.main')

@section('content')
    <h1>Settings</h1>
    <p>{{ $user->name }}</p>
@endsection

@yield can take a default value if the child never defines that section.

Convention

A template using @extends should contain only @section blocks. Markup outside a section is silently discarded because it doesn't get captured.