正确使用Blade(Laravel),在其自己的文件中包含标头时遇到问题

阿斯洛夫曼

我以为我会从刀片模板中拆分页眉,并分别包含页眉和页脚。它的工作原理是将header.blade.php放入layouts / partials /,然后在下一个模板中扩展layouts.partials.header。它可以工作,但是样式表和脚本会在内容之后加载。如何以快速且正确的顺序运行该组织?

header.blade.php

@section('header')
<!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>
@show

@section('footer')
    @section('scripts')
    @show
</body>
</html>
@show

master.blade.php

@extends('layouts.partials.header')
@yield('header')

    <div class="container">

        @section('topNav')
            <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>
        @show

        @yield('content')

        <div class="center-block login">
            @yield('login')
        </div>

    </div>

    @section('scripts')
    @show

</body>
</html>

home.blade.php

@extends('layouts.master')

    @section('title')
    @parent
        ::Home
    @stop

    @section('navTitle')
    @parent
        Mumble
    @stop

    @section('login')

            @if (Auth::check()) 
                <div class="col-md-12 panel panel-default">
                    <div class="panel-body text-center">
                        <h4>Welcome back  <em>{{ Auth::user()->name }}</em></h4>
                    </div>
                </div>

                <div class="text-center">
                    <a href="logout" class="btn btn-warning">Logout</a>
                </div>
            @else

                @if($error) 
                    <div class="alert alert-danger">
                        {{ $error }}
                    </div>
                @endif

                @if($errors->first('email'))
                    <div class="alert alert-warning">
                        {{ $errors->first('email') }}
                    </div>
                @endif
                @if($errors->first('password'))
                    <div class="alert alert-warning">
                        {{ $errors->first('password') }}
                    </div>
                @endif
                {{ Form::open(array('url' => '')) }}
                    <div class="form-group">
                        {{Form::label('email', 'Email')}}
                        {{Form::text('email', Input::old('email'),array('class'=>'form-control','placeholder'=>'enter email'))}}
                    </div>
                    <div class="form-group">
                        {{Form::label('password', 'Password')}}
                        {{Form::password('password',array('class'=>'form-control','placeholder'=>'enter password'))}}
                    </div>
                    <div class="form-group">

                        {{ Form::checkbox('remember','remember') }}  
                        <span style="margin-left:5px;">Remember Me</span>
                    </div>
                    <div class="text-center">
                        {{ Form::submit('Login',array('class'=>'btn btn-default')) }}
                    </div>
                {{ Form::close() }}
            @endif

    @stop

    @section('scripts')
        <script type="text/javascript">
            $(document).ready(function(){
                //$('.indexWrapper').addClass('homeCenter');
                //$('.indexWrapper').css( 'margin-top', '25%' );
            });
        </script>
    @stop

刀片中的组件应该如何模块化?我会把它分成太多吗?当脚本位于“页脚”(在页眉部分中定义,我想我应该重命名)时,它们运行缓慢,但是我只想知道是否有一种方法可以正确地执行此操作。

c-格里芬

对于我的项目,我通常会做这样的事情,效果很好。粒度的大小实际上取决于您自己的要求。

而不是使用@extends等。将视图设置为主布局的属性,以便在控制器中呈现它们。

master.blade.php

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sitename | @yield('title')</title>

    {{ stylesheet() }}

</head>
<body class="{{ $authClass }}{{ isset($bodyClass) ? $bodyClass : ''  }}" role="document">

    {{ $mainNav }}

    <section id="content">

        <section id="main">
            @yield('content')
        </section>

    </section>

    <footer></footer>
    {{ script('jQuery-2-0-3.min.js') }}
    {{ script('bootstrap.js') }}
</body>
</html>

将其添加到您的基本控制器中:如果存在,它会被Laravel自动调用

protected function setupLayout()
{

    $this->layout = View::make('layouts.master');

}

控制器方法(嵌套视图)

public function index()
{

    $this->layout->content = View::make('public.interior.index')
                                ->nest('content', 'components.login')
                                ->nest('sideBar', 'components.sidebars.interiorSidebar1', ['extra' => View::make('components.sidebars.extra.extra1')]);

}

索引视图(父视图.. @section已定义):

@section('content')

    <div class="row-fluid col-md-7 col-sm-12 col-md-offset-1 col-sm-offset-0">
        {{ $content }}
    </div>

    <div class="row-fluid col-md-3 col-sm-12 col-md-offset-1 col-sm-offset-0 pull-right">
        {{ $sideBar }}
    </div>

@stop

嵌套视图(组件类型的东西。未定义@section)

{{ Form::open(['class' => 'form-horizontal', 'role' => 'form']) }}
    <h2>User Login</h2>
    <div class="form-group">
        {{ Form::label('email', 'Email:', ['class' => 'col-sm-2 control-label']) }}
        <div class="col-sm-10">
            {{ Form::text('email', null, ['id' => 'email','class' => 'form-control']) }}
        </div>
    </div>
    <div class="form-group">
        {{ Form::label('password', 'Password:', ['class' => 'col-sm-2 control-label']) }}
        <div class="col-sm-10">
            {{ Form::text('password', null, ['class' => 'form-control']) }}
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            {{ Form::submit('Login', ['class' => 'btn btn-primary']) }}
             <a href="#" class="btn btn-default">Forgot Password</a>
        </div>
    </div>

{{ Form::close() }}

然后,哦,太神奇了……查看作曲家:创建composers.php文件并将其包含以将数据绑定到某些视图

View::composer(['layouts.master'], function($view){

    if(Auth::check()){
        $authClass = 'logged-in';
    } else {
        $items          = MenuMaker::getPublic();

        $authClass = 'logged-out';

        $view->with('mainNav', View::make('components.mainNavPublic', ['items' => $items]))
                ->with('authClass', $authClass);
    }

});

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用Git从跟踪中删除文件时遇到问题

来自分类Dev

在 PHP 中为多维数组使用正确的语法时遇到问题?

来自分类Dev

在MATLAB中从文件列表打开文件时遇到问题

来自分类Dev

使用XAMPP跨文件使用$ _POST时遇到问题

来自分类Dev

在Laravel中创建用户时遇到问题

来自分类Dev

使用Shell命令在VB中的文件路径中使用变量时遇到问题

来自分类Dev

我在使用laravel的AJAX发布时遇到问题

来自分类Dev

在熊猫中写入文件时遇到问题

来自分类Dev

在ColdFusion中确定文件的MIME类型时遇到问题

来自分类Dev

在处理3中运行.mov文件时遇到问题

来自分类Dev

在ColdFusion中确定文件的MIME类型时遇到问题

来自分类Dev

在eclipse中读取文件时遇到问题

来自分类Dev

我在 Python 中循环上传文件时遇到问题?

来自分类Dev

当前在从文件中删除/覆盖时遇到问题

来自分类Dev

在 Rmd 中获取文件时遇到问题

来自分类Dev

在Ubuntu上使用PHP写入文件时遇到问题

来自分类Dev

使用OpenXML SDK读取Excel文件时遇到问题

来自分类Dev

使用getline读取.csv文件时遇到问题

来自分类Dev

尝试使用vtkOBJWriter输出文件时遇到问题

来自分类Dev

在Ubuntu上使用PHP写入文件时遇到问题

来自分类Dev

使用txt / json文件时遇到问题

来自分类Dev

使用 getResource().readText() 读取 xml 文件时遇到问题

来自分类Dev

在Swift 2.0中使用基本文件系统功能时遇到问题

来自分类Dev

使用Java在Windows中创建新文件夹时遇到问题

来自分类Dev

尝试使用Windows搜索来搜索内容中带有问号的文件时遇到问题

来自分类Dev

使用vbscript替换文件中的字符串时遇到问题

来自分类Dev

使用Xcopy在批处理文件中复制到网络路径时遇到问题

来自分类Dev

路由问题,在 Laravel 中遇到问题

来自分类Dev

创建Laravel查询时遇到问题

Related 相关文章

  1. 1

    使用Git从跟踪中删除文件时遇到问题

  2. 2

    在 PHP 中为多维数组使用正确的语法时遇到问题?

  3. 3

    在MATLAB中从文件列表打开文件时遇到问题

  4. 4

    使用XAMPP跨文件使用$ _POST时遇到问题

  5. 5

    在Laravel中创建用户时遇到问题

  6. 6

    使用Shell命令在VB中的文件路径中使用变量时遇到问题

  7. 7

    我在使用laravel的AJAX发布时遇到问题

  8. 8

    在熊猫中写入文件时遇到问题

  9. 9

    在ColdFusion中确定文件的MIME类型时遇到问题

  10. 10

    在处理3中运行.mov文件时遇到问题

  11. 11

    在ColdFusion中确定文件的MIME类型时遇到问题

  12. 12

    在eclipse中读取文件时遇到问题

  13. 13

    我在 Python 中循环上传文件时遇到问题?

  14. 14

    当前在从文件中删除/覆盖时遇到问题

  15. 15

    在 Rmd 中获取文件时遇到问题

  16. 16

    在Ubuntu上使用PHP写入文件时遇到问题

  17. 17

    使用OpenXML SDK读取Excel文件时遇到问题

  18. 18

    使用getline读取.csv文件时遇到问题

  19. 19

    尝试使用vtkOBJWriter输出文件时遇到问题

  20. 20

    在Ubuntu上使用PHP写入文件时遇到问题

  21. 21

    使用txt / json文件时遇到问题

  22. 22

    使用 getResource().readText() 读取 xml 文件时遇到问题

  23. 23

    在Swift 2.0中使用基本文件系统功能时遇到问题

  24. 24

    使用Java在Windows中创建新文件夹时遇到问题

  25. 25

    尝试使用Windows搜索来搜索内容中带有问号的文件时遇到问题

  26. 26

    使用vbscript替换文件中的字符串时遇到问题

  27. 27

    使用Xcopy在批处理文件中复制到网络路径时遇到问题

  28. 28

    路由问题,在 Laravel 中遇到问题

  29. 29

    创建Laravel查询时遇到问题

热门标签

归档