【问题标题】:Breaking layouts into partials in Laravel 4 / Blade在 Laravel 4 / Blade 中将布局分解为部分
【发布时间】:2014-10-14 01:49:49
【问题描述】:

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

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>

然后,扩展它,是单个页面视图。不过,我想将主布局的页眉和页脚分开

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

【问题讨论】:

    标签: php laravel-4 blade


    【解决方案1】:

    基本功能是使用包含,这将抓取要包含的文件,并将不是内容放在包含标记的位置。

    ma​​ster.blade.php(放在“views/”文件夹下)

    <!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(放在“views/layout/”文件夹下)

    <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 遵循与页脚页眉相同的原则。

    希望这有帮助!

    【讨论】:

    • 完美。您是否会说这会对加载速度产生重大影响(负面或正面)?
    • 我还没有真正测试过,但它可能会......因为您需要获取两个或三个多个文件来创建一个页面。您可以使用 chome 或 firefox 中的网络工具检查这一点,并检查请求和页面加载之间的延迟。
    猜你喜欢
    • 2014-03-20
    • 2017-01-07
    • 2017-06-21
    • 1970-01-01
    • 2017-07-18
    • 2023-03-19
    • 1970-01-01
    • 2021-07-06
    • 2017-12-12
    相关资源
    最近更新 更多