[Flow] [Fluid] How can I use dynamic array indexes in templates?
Bastian Waidelich
bastian at typo3.org
Wed Jun 12 10:29:50 CEST 2013
Pavlina wrote:
Hi Pavlina,
> that it's not possible to use dynamic array indexes in templates. But I
> need it very much. I have an array of arrays - items, grouped by week
> day - and I need to dynamically access each sub-array trough a weekDay
> variable and iterate it with the foreach view helper.
Probably not the reply you want to hear, but: Use objects and your life
will be easier. Using array as wrappers for structural data is a common
thing to do (in the PHP world that is) but it is very error prone and
hard to comprehend & extend.
If you use a proper model (and that can be just a DTO[1]) your template
could look something like:
<f:for each="{calendar.weeks}" as="week">
<ul class="week">
<f:for each="{week.tasks}" as="task">
<li class="task">
{task.name}
</li>
</ul>
</f:for>
Rather than some complex nesting of ViewHelpers.
If you write a bit more about your intention we might be able to help
you defining the object(s) that represent your domain.
[1] http://en.wikipedia.org/wiki/Data_transfer_object
--
Bastian Waidelich
--
Core Developer Team
TYPO3 .... inspiring people to share!
Get involved: typo3.org
More information about the Flow
mailing list