My scenario:
<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>
Now when there are no users I have an ugly table, so I’ll add:
{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}
But now my {foreachelse} is useless.
So I delete the {foreachelse} There are no users.... part and conclude that {foreachelse} is useless.
This problem I have in <table>, <ol>, <ul> etc..
Does anyone have a solution so I’m able to use {foreachelse}?
Thanks!
You can have one row which says there are no users, eg:
But I can understand it when this is not the desired result.
Sometimes you might use divs in a foreach instead of table or lists contents. Check the smarty documentation on this:
http://www.smarty.net/docs/en/language.function.foreach.tpl