dbj44
dbj44

Reputation: 1998

How to use @yield and @extends in blade templates

master.blade.php

<div>
  @yield('content')
</div>

index.blade.php

@extends('layouts.master')
@section('content')
  <p>Foo</p>
@endsection

Folder structure

_layouts
__master.blade.php
_posts
__index.blade.php

When I do return view('layouts.master') I get nothing. I'm expecting 'Foo' to be printed.

What am I doing wrong? Thanks.

Upvotes: 0

Views: 2905

Answers (1)

Jerodev
Jerodev

Reputation: 33186

You need to return the index.blade.php view, this is the view that is inheriting the layout.

return view('posts.index');

Upvotes: 1

Related Questions