刀片模板结构 - 如何放置页眉和页脚等固定部分

时间:2014-01-23 09:10:40

标签: php laravel templating blade

这是我的情景:

我制作了一个main.blade.php,它包含以下代码:

<!DOCTYPE html>
<html>
    <head>
        <title>{{ $title }}</title>
    </head>
    <body>
        <div id='header'>
            @yield('header')
        </div>
        <div id='main-wrapper'>
             @yield('content')
        </div>
        <div id='footer'>
            @yield('footer')
        </div>
    </body>
</html>

然后这是控制器:

class Userindex extends BaseController
{
    protected $layout = "main";
    function register ()
    {
        $this->layout = View::make("user.register")
               ->with("title","Registration"); 
    }
}

这是user文件夹中的register.blade.php:

@extends('main')

@section('content')
    <p>This the content of the page register.</p>
@stop

我的问题:我还有另外两个页面如header.blade.php和footer.blade.php,我不知道如何将它们包含在register.blade.php中

1 个答案:

答案 0 :(得分:2)

对布局文件做一点调整,用@include替换@yield,就是这样!

<!DOCTYPE html>
<html>
    <head>
        <title>{{ $title }}</title>
    </head>
    <body>
        <div id='header'>
            @include('partials.header')
        </div>
        <div id='main-wrapper'>
             @yield('content')
        </div>
        <div id='footer'>
            @include('partials.footer')
        </div>
    </body>
</html>
相关问题