我的情景:Smarty {foreachelse}有什麼用?
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
{foreach from=$users item=user}
<tr>
<td>{$user.name}</td>
<td>{$user.email}</td>
</tr>
{foreachelse}
There are no users....
{/foreach}
</tbody>
</table>
現在,當沒有用戶我有一個醜陋的表,所以我會補充:
{if $users|count > 0}
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
{foreach from=$users item=user}
<tr>
<td>{$user.name}</td>
<td>{$user.email}</td>
</tr>
{foreachelse}
There are no users....
{/foreach}
</tbody>
</table>
{else}
There are no users....
{/if}
但現在我的{foreachelse}
是沒用的。
因此,我刪除{foreachelse} There are no users....
部分,並得出結論{foreachelse}
是無用的。
這個問題我已經在<table>
,<ol>
,<ul>
等。
有誰有解決的辦法,所以我能夠使用{foreachelse}
?
謝謝!
不知道我明白。爲什麼該方法僅僅因爲您可以使用其他方法而無用? –
不,因爲我僅使用'{foreach}'來創建表或列表。在這種情況下,{foreachelse}無用(或者有人知道更好的解決方案)。 –
當你想/需要輸出一行表示沒有行時,foreachelse很有用。非常方便的結構,你必須有一張桌子,不管是什麼。 – BoltClock