[TYPO3-mvc] Fluid - is there a way to check if an object is the first or last object?
Stephen Bungert
stephen at bungert.co.uk
Sun Jul 18 17:45:30 CEST 2010
I want to add the classes "first" or "last" to a tag in my template, how
can I check if the current object in a for tag/loop is the last or first?
I thought about doing something like this:
public function listAction() {
$objects = $this->itemRepository->findAll();
$numOfObjects = count($objects);
foreach($objects as $key => &$value) {
$value->numOfObjects = $numOfObjects;
if ($key == 0) {
$value->position = 'first ';
} else if ($key == $numOfObjects - 1) {
$value->position = 'last ';
} else {
$value->position = '';
}
}
$this->view->assign('items', $objects);
}
This works, the new properties are added and in my fluid template I just
have to add {item.position}, or so I thought:
<f:for each="{items}" as="item">
<f:debug>{item}</f:debug>
<f:cycle values="{0: 'odd', 1: 'even'}" as="oddEven">
<li class="item{item.uid} {item.position}{oddEven}{item.classes}">
</f:cycle>
In the debug I see my properties, but {item.position} is always rendered
empty, I guess because the value has to be in _cleanProperties?
Does anyone know how I can do what I want or have any suggestions?
More information about the TYPO3-project-typo3v4mvc
mailing list