【发布时间】:2016-07-24 11:27:11
【问题描述】:
我的刀片布局文件和刀片视图中有两个表格的代码。有没有办法减少我重复的代码量?下面是我的布局文件中的代码。 有没有办法让布局文件中的第一个表,然后传递不同的变量以在刀片视图文件中创建多个不同的表? 基本上我可以使用布局中第一个表的代码来重新创建刀片视图文件中的第二个表吗?
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<table border = "1", cellspacing = "2", align = center>
<tr> <td> <strong> ID </strong></td> <td><strong> Time </strong></td><td> <strong> Note </strong></td></tr>
<!-- blade for loop -->
@for ($i=0; $i <$countOfUniqueDate[$uniqueDates[0]]; $i++)
<tr><td> {{ $number[$i] ->id }} </td><td> {{ $number[$i]->timevalue }} </td> <td> {{ $number[$i]->note }} </td></tr>
@endfor
</table>
@yield('table')
//I would like to get rid of the below code by reusing the above table code
// to recreate the second table
<br><br><br>
<table border = "1", cellspacing = "2", align = center>
<tr> <td> <strong> ID </strong></td> <td><strong> Time </strong></td><td> <strong> Note </strong></td></tr>
@for($i= $countOfUniqueDate[$uniqueDates[0]]; $i < ($countOfUniqueDate[$uniqueDates[0]] + $countOfUniqueDate[$uniqueDates[1]]); $i++)
<tr><td> {{ $number[$i] ->id }} </td><td> {{ $number[$i]->timevalue }} </td><td> {{ $number[$i]->note }} </td></tr>
@endfor
</table>
<br><br><br><br><br>
@yield('table2')
</body>
<br><br>
</html>
这是我的刀片视图文件中的代码。
<!DOCTYPE html>
<html>
@extends("layouts.practice")
@section('table')
@stop
<p align="center">
<a href="https://villageprintwebapp.app/writeNote"> Add a comment </a>
</p>
</html>
我也可以在不引用 section('table2') 的情况下显示两个表,但不确定它是如何工作的。
【问题讨论】:
-
我不明白。能否更具体地说明您想要实现的目标?
-
我也搞不定
-
有没有办法通过重用第一个表的代码来制作第二个表?
-
也许使用
@include('table', $paramsAsArray)而不是@yield? -
这是你的答案吗? laravel.com/docs/5.2/blade#control-structures -- 向下滚动到“包含子视图”