Typo3 Fluid:如果是第一个,则将类添加到元素

Sim*_*mon 1 typo3 fluid

我正在使用Fluid将Contentelments送入扩展:

<f:for each="{field.children}" as="myObj" iteration="iterator">
  {myObj.render -> f:format.raw()}
</f:for>
Run Code Online (Sandbox Code Playgroud)

这工作正常.

元素看起来像这样:

<div class="childElement">
  <h1>I'm a Caption!</h1>
  <p>I'm some text.....</p>
</div>
Run Code Online (Sandbox Code Playgroud)

然后以某种方式显示元素.

现在我希望第一个Element一个名为" first "的额外类.然后第一个元素看起来像这样:

<div class="childElement first">
  <h1>I'm a Caption!</h1>
  <p>I'm some text.....</p>
</div>
Run Code Online (Sandbox Code Playgroud)

我尝试使用迭代器解决这个问题,并简单地检查迭代器是否"isfirst".像这样的东西:

<f:for each="{field.children}" as="myObj" iteration="iteration">
 <f:if condition="iteration.isFirst">
    <f:then>
     ...
Run Code Online (Sandbox Code Playgroud)

但是我仍然需要插入课程,无论如何感觉必须有更好的方法来解决它.

有人可能会指出我正确的方向吗?


编辑(解决方案):

在我做"<div class="childElement">"了扩展而不是在Child中进行了包装后,接受的答案对我有用.我的解决方案现在看起来像这样

<f:for each="{field.children}" as="myObj" iteration="iterator">
  <div class="childElement {f:if(condition:iterator.isFirst, then: ' first')}">
     {childDce.render -> f:format.raw()}
   </div>
</f:for>
Run Code Online (Sandbox Code Playgroud)

The*_*e F 6

您可以简单地使用f:的内联版本:if viewhelper以避免在<f:then>- > <f:else>构造中重复自己:

<f:for each="{field.children}" as="myObj" iteration="iter">
    <div class="childElement{f:if(condition:iter.isFirst, then: ' first')}">
Run Code Online (Sandbox Code Playgroud)

由于你没有其他情况,你可以放弃它.根据您的流体版本,您可能需要使用更多花括号来包装条件表达式,如下所示:

<f:for each="{field.children}" as="myObj" iteration="iter">
    <div class="childElement{f:if(condition: '{iter.isFirst}', then: ' first')}">
Run Code Online (Sandbox Code Playgroud)

但这不应该是必要的(虽然它有效).