我需要在刀片模板中输出各种@foreach循环,但是它们都针对数据库中相同的表,只是获取不同的字段。例如,我在我的主布局中使用了“产生”,在标题/描述标签的视图中使用了@节等等:
@section('title')
@foreach($store_listings as $fetch)
Website stores - {{ $fetch->city }}, {{ $fetch->country }}
@endforeach
@stop
@section('description')
@foreach($store_listings as $fetch)
List of Stores in {{ $fetch->city }}, {{ $fetch->country }}.
@endforeach
@stop然后在layout.main中:
<title>@yield('title')</title>和
<meta name="description" content="@yield('description')" />这个重复的@foreach循环出现在我在其他页面上视图的其他部分中。我试着用干燥的方法工作。当我只想调用一些变量时,这里有什么建议可以帮助我进入多个foreach循环呢?我也不想让我的负责人来处理这件事。
谢谢
发布于 2014-03-11 14:31:41
在本例中,您可以做的一件事是使用一个部分,比如views/_partials/storeList.blade.php
@foreach($store_listings as $fetch)
{{$title}} {{ $fetch->city }}, {{ $fetch->country }}
@endforeach然后,在你的主要观点中,你只需称之为:
@include('_partials.storeList', array('title' => 'Website stores -'))
@include('_partials.storeList', array('title' => 'List of Stores in'))https://stackoverflow.com/questions/22328511
复制相似问题