[TYPO3-mvc] fluid: adding own variables [discussion]
Bastian Waidelich
bastian at typo3.org
Fri Jul 17 10:40:56 CEST 2009
Christian Zenker wrote:
Hi Christian,
> Today was the first day I used Fluid. And let me say - I really love it.
> It's simple, easy to learn and powerfull.
Glad, that you like it!
> So it would be nice to have an opportunity to create own variables on
> runtime in the template.
Good that you bring up this topic. I'm just thinking about missing view
helpers for Fluid & tx_fluid (will open-up a new thread on this one).
We definitely need something like alternating classes. And though it's
technically no problem, I think we have to find a cleaner way to
implement this feature because having too much power in you view leads
to diffusion of the tiers of your extension. Don't get me wrong: In your
example it's absolutely legitimate as it's only used for presentation
logic. But I'm sure people would use a register for business/control
logic soon if we'd provide it as "official" view helper, leading to more
complex and unmaintainable extensions.
Furthermore your example get's considerably more complex by adding the
zebra classes.
From:
<ul>
<f:for each="{0 : 'one', 1 : 'two', 2 : 'three', 3 : 'four'}"
as="item" key="key">
<li class="{zebra}">
{item}
...do some more stuff...
</li>
</f:for>
</ul>
To:
<ul>
<f:for each="{0 : 'one', 1 : 'two', 2 : 'three', 3 : 'four'}"
as="item" key="key">
<f:register.storage>
<f:if condition="{key}%2">
<f:then>
<f:register.add variables="{'zebra' : 'even', 'foo' : 'bar'}" />
</f:then>
<f:else>
<f:register.add variables="{'zebra' : 'odd', 'foo': 'baz'}" />
</f:else>
</f:if>
<li class="{zebra}">
{item}
...do some more stuff...
</li>
</f:register.storage>
</f:for>
</ul>
To keep a long story short: As Steffen already proposed, we need a
rotate view helper. Though I'd prefer the name "cycle":
<f:cycle name="zebra" values="{0: 'odd', 1: 'even'}">
<li class="{zebra}">foo</li>
</f:cycle>
Bastian
More information about the TYPO3-project-typo3v4mvc
mailing list