Given the following base layout and child view, what will be the final rendered HTML?
@extends('layouts.master') @section('title', 'Home Page') @section('content') <p>Welcome to the home page!</p> @endsection // layouts/master.blade.php <html> <head> <title>@yield('title', 'Default Title')</title> </head> <body> <div class="content"> @yield('content') </div> </body> </html>
Remember that @section content replaces @yield in the parent layout.
The child view sets the title section to 'Home Page' and defines the content section with a paragraph. The parent layout uses @yield to insert these sections. So the final HTML includes the title 'Home Page' and the paragraph inside the content div.
In Laravel Blade, you want to define a section called sidebar that can be overridden by child views but has default content if not overridden. Which option is correct?
Use @section with @show to define default content that can be replaced.
Option A uses @section with @show, which outputs the section content immediately and allows child views to override it. Option A defines a section but does not output it. Option A uses @yield which is for displaying sections, not defining them. Option A misuses @extends.
Consider this parent layout and child view. The child content inside @section('content') does not appear in the rendered page. What is the cause?
// layouts/app.blade.php
<html>
<head><title>App</title></head>
<body>
<div>@yield('content')</div>
</body>
</html>
// child.blade.php
@extends('layouts.app')
@section('content')
<p>Child content here</p>
@stopCheck if the section closing directive matches the Blade syntax.
In Laravel Blade, @stop is an alias for @endsection and should work, but if the Blade version or configuration does not support @stop, the section may not render. The safest is to use @endsection. Options B, C, and D misunderstand how sections and yields work.
Given the parent layout and child view below, what will be the rendered output inside the content div?
// layouts/base.blade.php
<html>
<body>
<div>@yield('content')</div>
</body>
</html>
// child.blade.php
@extends('layouts.base')
@section('content')
<p>Start</p>
@parent
<p>End</p>
@endsectionRemember that @parent inserts the parent section content.
The parent layout has no content in the content section, so @parent inserts nothing. The child section outputs
Start
thenEnd
. The final output inside the div is both paragraphs without extra blank lines.Choose the correct statement about how @extends, @section, and @yield work together in Laravel Blade templates.
Think about which directive is responsible for outputting section content.
@yield is used in parent templates to display content defined by @section in child views. @extends specifies the parent template to inherit from. @section defines content blocks. Option A correctly describes this relationship.