我正在使用Laravel 5.0编写一个网页,并希望模块化视图的各个部分。 目前我有主人>> view>>部分模板。
master.blade.php
<head> <!-- master's css --> @yield('css') </head> <body> @yield('content') </body>
view.blade.php
@extends('master') @section('css') <!-- view-specific css --> @stop @section('content') <!-- some content --> @include('partial') @stop
partial.blade.php
@section('css') @parent <!-- partial-specific css --> @append <!-- partial's content -->
如何加载:
<head> <!-- master's css --> <!-- view-specific css --> <!-- partial-specific css --> </head>
我希望如何加载:
<head> <!-- master's css --> <!-- partial-specific css --> <!-- view-specific css --> </head>
我尝试在@parent
之前和之后移动view-specific css
,但无论如何,页面都会在视图css之后加载partial-specific css
。
我的理由是,我希望视图模板中的最后一个css表是最后一个加载的,这样如果需要使用它的特定页面,我可能会覆盖部分的部分css。
提前致谢。
答案 0 :(得分:0)
更好的方法是partial
扩展view
:
主强>
<head>
<!-- master's css -->
@yield('css')
</head>
<body>
@yield('content')
</body>
查看强>
@extends('master')
@section('css')
<!-- view-specific css -->
@stop
@section('content')
<!-- some content -->
@stop
<强>部分强>
@extends('view')
@section('css')
<!-- partial-specific css -->
@parent
@stop
@section('content')
@parent
<!-- partial's content -->
@stop
你的输出将是:
<head>
<!-- master's css -->
<!-- partial-specific css -->
<!-- view-specific css -->
</head>
<body>
<!-- some content -->
<!-- partial's content -->
</body>
而不是return view('view');
你会return view('partial');
在你的情况下这样做可能没有意义,但你会得到理想的结果。