This commit is contained in:
bzick 2016-05-08 00:33:23 +03:00
parent ba4ba548ff
commit e289b9b3b1
2 changed files with 39 additions and 8 deletions

View File

@ -37,6 +37,12 @@ The next form will additionally assign the current element's key to the `$key` v
Gets the current array index, starting with zero.
```smarty
{foreach $list as $value}
<div>№{$value@index}: {$value}</div>
{/foreach}
or
{foreach $list as $value index=$index}
<div>№{$index}: {$value}</div>
{/foreach}
@ -45,22 +51,34 @@ Gets the current array index, starting with zero.
Detect first iteration:
```smarty
{foreach $list as $value}
<div>{if $value@first} first item {/if} {$value}</div>
{/foreach}
or
{foreach $list as $value first=$first}
<div>{if $first} first item {/if} {$value}</div>
{/foreach}
```
`$first` is `TRUE` if the current `{foreach}` iteration is the initial one.
`$first` is `TRUE` if the current `{foreach}` iteration is first iteration.
Detect last iteration:
```smarty
{foreach $list as $value}
<div>{if $value@last} last item {/if} {$value}</div>
{/foreach}
or
{foreach $list as $value last=$last}
<div>{if $last} last item {/if} {$value}</div>
{/foreach}
```
`$last` is set to `TRUE` if the current `{foreach}` iteration is the final one.
`$last` is set to `TRUE` if the current `{foreach}` iteration is last iteration.
### {break}

View File

@ -38,11 +38,12 @@
{/foreach}
```
Получение номера (индекса) итерации, начиная с 0
```smarty
{foreach $list as $value}
<div>№{$value:index}: {$value}</div>
<div>№{$value@index}: {$value}</div>
{/foreach}
или
@ -52,20 +53,32 @@
{/foreach}
```
Определение первого элемента
Определение первой итерации:
```smarty
{foreach $list as $value}
<div>{if $value:first} first item {/if} {$value}</div>
<div>{if $value@first} first item {/if} {$value}</div>
{/foreach}
или
{foreach $list as $value first=$first}
<div>{if $first} first item {/if} {$value}</div>
{/foreach}
```
Переменная `$value:first` будет иметь значение **TRUE**, если текущая итерация является первой.
Определение последнего элемента
Переменная `$value@first` будет иметь значение **TRUE**, если текущая итерация является первой.
Определение последней интерации:
```smarty
{foreach $list as $value}
<div>{if $value:last} last item {/if} {$value}</div>
<div>{if $value@last} last item {/if} {$value}</div>
{/foreach}
или
{foreach $list as $value last=$last}
<div>{if $last} last item {/if} {$value}</div>
{/foreach}
```