在Laravel 4 / Blade中将布局分解为局部

时间:2014-08-20 15:52:42

标签: php laravel-4 blade

无法将我的观点分解为一些不那么多余的东西。现在,这是典型布局的外观:

master.blade.php:

<!DOCTYPE html>
<html>
<head>
<title>
@section('title')
@show
</title>  
<script type="text/javascript" src="{{ asset('bower/jquery/dist/jquery.min.js') }}"></script>
<link href="{{ asset('bower/bootstrap/dist/css/bootstrap.min.css') }}" rel="stylesheet">
<script type="text/javascript" src="{{ asset('bower/bootstrap/dist/js/bootstrap.min.js') }}"></script>
<script type="text/javascript" src="{{ asset('bower/ckeditor/ckeditor.js') }}"></script>
<link href="{{ asset('css/default.css') }}" rel="stylesheet"> 
</head>
<body>
<div class="container">
    <div class="row center-block text-center indexWrapper">
        <div class="indexNav">
            <ul class="text-right">
                <li><a href="{{URL::to('people')}}">People</a></li>
                <li><a href="{{URL::to('bulletin')}}">Bulletin</a></li>
                <li><a href="{{URL::to('current')}}">Current</a></li>
                <li><a href="{{URL::to('finished')}}">Finished</a></li>
            </ul>
        </div>
        <div class="indexHeading">
            <h1 class="indexH1">
                @section('navTitle')
                @show
            </h1>
        </div>
        <div class="clearfix"></div>
    </div>
    @yield('content')
    <div class="center-block login">
        @yield('login')
    </div>
</div>
    <div class="row center-block footer">
    <hr>
        <ul>
        <small>
            <li><span style="color:red">DEVELOPMENT MODE</span></li>
            <li>Mumble &copy; 2014</li>
            <li><a href="">Follow project on GitHub</a></li>
        </small>
        </ul>
    </div>
    @section('scripts')
    @show
</body>
</html>

然后,扩展它,是单个页面视图。我想通过

分隔主布局的页眉和页脚

在刀片中进行有效模板化的最佳方法是什么?

1 个答案:

答案 0 :(得分:1)

基本功能是使用包含,这将获取文件以包含并放置内容以代替包含标记。

master.blade.php (位于&#39; views /&#39;文件夹下)

<!DOCTYPE html>
<html>
    <head>
        <title>
            @section('title')
            @show
        </title>  
        @include('layout.header')
    </head>
    <body>
        <div class="container">
            <div class="row center-block text-center indexWrapper">
                <div class="indexNav">
                    <ul class="text-right">
                        <li><a href="{{URL::to('people')}}">People</a></li>
                        <li><a href="{{URL::to('bulletin')}}">Bulletin</a></li>
                        <li><a href="{{URL::to('current')}}">Current</a></li>
                        <li><a href="{{URL::to('finished')}}">Finished</a></li>
                    </ul>
                </div>
                <div class="indexHeading">
                    <h1 class="indexH1">
                        @section('navTitle')
                        @show
                    </h1>
                </div>
                <div class="clearfix"></div>
            </div>
            @yield('content')
            <div class="center-block login">
                @yield('login')
            </div>
        </div>
        <div class="row center-block footer">
        <hr>
            <ul>
            <small>
                <li><span style="color:red">DEVELOPMENT MODE</span></li>
                <li>Mumble &copy; 2014</li>
                <li><a href="">Follow project on GitHub</a></li>
            </small>
            </ul>
        </div>
        @section('scripts')
        @show
    </body>
</html>

header.blade.php (位于&#39; views / layout /&#39;文件夹下)

<head>
    <title>
        @section('title')
        @show
    </title>  
    <script type="text/javascript" src="{{ asset('bower/jquery/dist/jquery.min.js') }}"></script>
    <link href="{{ asset('bower/bootstrap/dist/css/bootstrap.min.css') }}" rel="stylesheet">
    <script type="text/javascript" src="{{ asset('bower/bootstrap/dist/js/bootstrap.min.js') }}"></script>
    <script type="text/javascript" src="{{ asset('bower/ckeditor/ckeditor.js') }}"></script>
    <link href="{{ asset('css/default.css') }}" rel="stylesheet"> 
</head>

<强> footer.blade.php 遵循与页脚标题相同的原则。

希望这有帮助!