【问题标题】:Blade templating structure - how to put fixed sections such as header and footer刀片模板结构 - 如何放置页眉和页脚等固定部分
【发布时间】:2014-02-13 17:45:48
【问题描述】:

这是我的场景:

我制作了一个 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 中

【问题讨论】:

    标签: php laravel templating blade


    【解决方案1】:

    对你的布局文件做一点调整,用@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>
    

    【讨论】:

      猜你喜欢
      • 2016-05-31
      • 2018-10-13
      • 2014-07-10
      • 2023-03-17
      • 2014-11-05
      • 1970-01-01
      • 2013-08-30
      • 1970-01-01
      • 2014-07-07
      相关资源
      最近更新 更多