Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blade Template with comment on top not working

file: app/route.php

Route::get('/', function()
{
    return View::make('home');
});

file: app/views/home.blade.php

{{-- Blade comment. --}}
@extends('layouts.base')

@section('head')
    <link rel="stylesheet" href="second.css" />
@stop

@section('body')
    <h1>Heading</h1>
    <p>Hello Home!</p>
@stop

file: app/views/layouts/base.blade.php

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    @section('head')
    <link rel="stylesheet" href="style.css" />
    @show
</head>
<body>
    @yield('body')
</body>
</html>

When I access to laravel.localhost/ It only output @extends('layouts.base')

but however, if I remove the

{{-- Blade comment. --}}

then it works perfectly.

May I know what is the issue?

like image 565
Shiro Avatar asked Dec 05 '25 07:12

Shiro


2 Answers

The first line in your extended blade view must be the @extends directive.

like image 163
ObSeSSeN Avatar answered Dec 07 '25 04:12

ObSeSSeN


Yes it is a convention by the devs. Look at BladeCompiler.php on line 119.

protected function compileExtends($value)
    {
        // By convention, Blade views using template inheritance must begin with the
        // @extends expression, otherwise they will not be compiled with template
        // inheritance. So, if they do not start with that we will just return.
        if (strpos($value, '@extends') !== 0)
        {
            return $value;
        }
like image 23
Dustin Deus Avatar answered Dec 07 '25 05:12

Dustin Deus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!