工作,我有喜欢的结构部位:产量不节Laravel刀片
第一:master.blade.php
:这包含section('content')
<body>
@include('partial.header')
@yield('content')
@include('partial.footer')
</body>
二index.blade.php
:含有section('content')
。
@extends('layouts.master')
@section('content')
<div id="container">
<div id="news">
@yield('news')
</div>
<div id="apartment">
@yield('apartment')
</div>
</div> <!-- ./container -->
@endsection
三:news.blade.php
:这个简单的显示所有news
@foreach($posts as $post)
@endforeach
最终文件:apartment.blade.php
:这个简单的显示所有apartment
。
@foreach($apartments as $apartment)
@endforeach
我的路线直接到master.blade.php
。 我的问题是:
当我包括
news
在index.blade.php
@yield('news')
。它显示了我的数据库中正确的所有news
。 但是当我在index.blade.php
中删除@yield('news')
时。它也显示我的数据库中的news
(但它为此丢失了css/js)。 为什么我删除@yield('news')
,它应该在我的页面上不显示任何news
?似乎Laravel刀片不支持两个
@yield
在@section
。当我在index.blade.php
文件中只添加1行@yield('news')
时。它显示我的索引页上的列表新闻。当我继续添加@yield('apartment')
。索引页上没有显示任何公寓。我当然有它的价值,当foreach
来获取数据。我也用HTML静态测试,但没有任何更改。
如果你想添加其他模板使用include不包括包含部分模板 – Exprator
你的想法是:'@include('news')'? – vanloc
是的。这就是你如何包括。或者你可以搜索在laravel中包含模板,如果这不起作用 – Exprator