1

I've a list of objects (question-items), each with a property named category and title. (The list of objects is ordered by its category property)

With this Fluid Template I want to iterate over the question items:

<f:for each="{questions}" as="question">
   <!-- every time category changes, display it as a new headline ??? -->
   <!-- if (question.category != previousQuestion.category) ?.....? -->
   <span>{question.title}</span>
</f:for>

How can I check, if the category property has changed in the for? The output should be something like this:

  • Category-A
    • Question
    • Question
  • Category-B
    • Question
  • Category-C
    • Question
    • Question
    • Question
    • ...
4

1 回答 1

0

您正在寻找 f:groupedFor viewhelper:http ://docs.typo3.org/typo3cms/ExtbaseGuide/Fluid/ViewHelper/GroupedFor.html

<f:groupedFor each="{questions}" as="categoryQuestion" groupBy="category" groupKey="category">
    <h2>{category}</h2>
    <f:for each="{categoryQuestion}" as="question">
        <span>{question.title}</span>
    </f:for>
</f:groupedFor>

您使用<f:if>viewhelper 的方法不起作用,因为流体中没有真正的模板变量,只有 xml 范围内的“常量”,所以即使您通过<f:alias>viewhelper 定义了 previousQuestion,您也无法将其与当前值。

于 2014-08-04T11:49:53.063 回答