【发布时间】:2017-12-12 19:36:04
【问题描述】:
我的网站结构如下:
第一: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。
我的问题是:
当我在
index.blade.php中包含news和@yield('news')时。它在我的数据库中显示正确的所有news。 但是当我在index.blade.php中删除@yield('news')时。它还从我的数据库中显示news(但它丢失了css/js)。 为什么我删除了@yield('news'),它应该不会在我的页面上显示任何news?似乎 Laravel Blade 不支持
@section中的两个@yield。当我只将 1 行@yield('news')添加到index.blade.php文件中时。它在我的索引页面上显示列表新闻。当我继续添加@yield('apartment')。索引页面上没有显示任何公寓。我当然在foreach获取数据时具有价值。我也用 HTML 静态测试,但没有任何变化。
【问题讨论】:
-
如果你想添加其他模板使用 include 包含部分模板,它不会产生
-
你的想法是不是像:
@include('news')? -
是的。这就是你包括在内的方式。或者如果不起作用,您可以搜索在 laravel 中包含模板
-
@Exprator 结果一样。