我一直在尝试简单的刀片模板工作.这是代码:
routes.php文件
<?php
Route::get('/', function()
{
return View::make('hello');
});
Run Code Online (Sandbox Code Playgroud)
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
hello.blade.php
<!DOCTYPE html>
<html>
<head>
<title>swag</title>
</head>
<body>
hello
@yield('content')
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
content.blade.php
@extends('hello')
@section('content')
<p>content check</p>
@stop
Run Code Online (Sandbox Code Playgroud)
当我在浏览器中运行此代码时,所有内容都只是我在hello.blade.php中编写的hello文本,但yield('content')没有显示任何内容,我无法弄清楚原因.我很感激任何帮助,谢谢
tot*_*dli 12
您创建了错误的视图.父视图是hello,它不知道content.这就是为什么你写@extends('hello')这个,当你创建你的content视图时,它会知道它必须扩展的东西hello.
Route::get('/', function()
{
return View::make('content');
});
Run Code Online (Sandbox Code Playgroud)
对于所有为此苦苦挣扎的人,请确保您的模板 php 文件的名称包含刀片扩展名,例如:mytemplate.blade.php,如果您错误地将 .blade 扩展名保留了下来,您的模板将不会被正确解析。