mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API Introduce $FromEnd variable for iterators
This commit is contained in:
parent
2cc9d02f75
commit
e91606e494
@ -296,8 +296,11 @@ iteration.
|
|||||||
* `$Even`, `$Odd`: Returns boolean, handy for zebra striping
|
* `$Even`, `$Odd`: Returns boolean, handy for zebra striping
|
||||||
* `$EvenOdd`: Returns a string, either 'even' or 'odd'. Useful for CSS classes.
|
* `$EvenOdd`: Returns a string, either 'even' or 'odd'. Useful for CSS classes.
|
||||||
* `$First`, `$Last`, `$Middle`: Booleans about the position in the list
|
* `$First`, `$Last`, `$Middle`: Booleans about the position in the list
|
||||||
* `$FirstLast`: Returns a string, "first", "last", or "". Useful for CSS classes.
|
* `$FirstLast`: Returns a string, "first", "last", "first last" (if both), or "". Useful for CSS classes.
|
||||||
* `$Pos`: The current position in the list (integer). Will start at 1.
|
* `$Pos`: The current position in the list (integer).
|
||||||
|
Will start at 1, but can take a starting index as a parameter.
|
||||||
|
* `$FromEnd`: The position of the item from the end (integer).
|
||||||
|
Last item defaults to 1, but can be passed as a parameter.
|
||||||
* `$TotalItems`: Number of items in the list (integer)
|
* `$TotalItems`: Number of items in the list (integer)
|
||||||
|
|
||||||
:::ss
|
:::ss
|
||||||
|
@ -460,3 +460,4 @@ coding conventions. E.g. `DB::requireTable` is now `DB::require_table`
|
|||||||
This is in order to promote better referencing of elements across the codebase.
|
This is in order to promote better referencing of elements across the codebase.
|
||||||
See `FulltextSearchable->enable` for example.
|
See `FulltextSearchable->enable` for example.
|
||||||
* `FormField` subclasses must now use `validate(Validator $validator)` as the interface has changed for this function
|
* `FormField` subclasses must now use `validate(Validator $validator)` as the interface has changed for this function
|
||||||
|
* `$FromEnd` iterator variable now available in templates.
|
||||||
|
@ -830,7 +830,19 @@ after')
|
|||||||
|
|
||||||
//test Pos
|
//test Pos
|
||||||
$result = $this->render('<% loop Set %>$Pos<% end_loop %>',$data);
|
$result = $this->render('<% loop Set %>$Pos<% end_loop %>',$data);
|
||||||
$this->assertEquals("12345678910",$result,"Even and Odd is returned in sequence numbers rendered in order");
|
$this->assertEquals("12345678910", $result, '$Pos is rendered in order');
|
||||||
|
|
||||||
|
//test Pos
|
||||||
|
$result = $this->render('<% loop Set %>$Pos(0)<% end_loop %>',$data);
|
||||||
|
$this->assertEquals("0123456789", $result, '$Pos(0) is rendered in order');
|
||||||
|
|
||||||
|
//test FromEnd
|
||||||
|
$result = $this->render('<% loop Set %>$FromEnd<% end_loop %>',$data);
|
||||||
|
$this->assertEquals("10987654321", $result, '$FromEnd is rendered in order');
|
||||||
|
|
||||||
|
//test FromEnd
|
||||||
|
$result = $this->render('<% loop Set %>$FromEnd(0)<% end_loop %>',$data);
|
||||||
|
$this->assertEquals("9876543210", $result, '$FromEnd(0) rendered in order');
|
||||||
|
|
||||||
//test Total
|
//test Total
|
||||||
$result = $this->render('<% loop Set %>$TotalItems<% end_loop %>',$data);
|
$result = $this->render('<% loop Set %>$TotalItems<% end_loop %>',$data);
|
||||||
|
@ -206,6 +206,7 @@ class SSViewer_BasicIteratorSupport implements TemplateIteratorProvider {
|
|||||||
'Odd',
|
'Odd',
|
||||||
'EvenOdd',
|
'EvenOdd',
|
||||||
'Pos',
|
'Pos',
|
||||||
|
'FromEnd',
|
||||||
'TotalItems',
|
'TotalItems',
|
||||||
'Modulus',
|
'Modulus',
|
||||||
'MultipleOf',
|
'MultipleOf',
|
||||||
@ -312,6 +313,17 @@ class SSViewer_BasicIteratorSupport implements TemplateIteratorProvider {
|
|||||||
return $this->iteratorPos + $startIndex;
|
return $this->iteratorPos + $startIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the position of this item from the last item in the list. The position of the final
|
||||||
|
* item is $endIndex, which defaults to 1.
|
||||||
|
*
|
||||||
|
* @param integer $endIndex Value of the last item
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function FromEnd($endIndex = 1) {
|
||||||
|
return $this->iteratorTotalItems - $this->iteratorPos + $endIndex - 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the total number of "sibling" items in the dataset.
|
* Return the total number of "sibling" items in the dataset.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user