duanqianruan8448 2014-08-20 15:52
浏览 74
已采纳

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

Having trouble breaking my views up into something a little less redundant. Right now, this is how a typical layout looks:

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>

And then, extending that, are the individual pages views. I would like to separate the header and footer of the master layout though

What is the best way of doing efficient templating in blade?

  • 写回答

1条回答 默认 最新

  • dqwcdqs358367 2014-08-26 15:06
    关注

    Basic functionality is using an include, this will grab the file to include and put is't content in place of the include tag.

    master.blade.php (placed under the 'views/' folder)

    <!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 (placed under the 'views/layout/' folder)

    <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 Follow the same principle as the header for your footer.

    Hope this helped!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制