I have been repeatedly trying to make simple blade template work. This is the code:
routes.php
<?php
Route::get('/', function()
{
return View::make('hello');
});
BaseController.php
<?php
class BaseController extends Controller {
/**
* Setup the layout used by the controller.
*
* @return void
*/
protected function setupLayout()
{
if ( ! is_null($this->layout))
{
$this->layout = View::make($this->layout);
}
}
}
hello.blade.php
<!DOCTYPE html>
<html>
<head>
<title>swag</title>
</head>
<body>
hello
@yield('content')
</body>
</html>
content.blade.php
@extends('hello')
@section('content')
<p>content check</p>
@stop
When I run this code in a browser, all there is is just hello text I wrote in hello.blade.php, however yield('content') does not display anything and I can't figure out why. I'd appreciate any help, thanks
For all of those struggling with this, make sure that your template php file is name with the blade extension in it, like so: mytemplate.blade.php, if you make the mistake of leaving the .blade extension out, you template will not be parsed correctly.
You created the wrong view. The parent view is hello
, it doesn't know about content
. That's why you wrote @extends('hello')
, that way when you create your content
view, it will know that it has to extend stuff from hello
.
Route::get('/', function()
{
return View::make('content');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With