0

Is there any possibilities tu use something like the alternating template parts in tx_news extension? In standard tt_news template I used to use <!-- ###NEWS_1###--> <!-- ###NEWS_2###--> <!-- ###NEWS_3###--> etc. In tx_news everything is in Fluid and I don't see anything similar to alternating template parts in manual.

Adrian
  • 992
  • 2
  • 16
  • 46
  • 1
    You can just do this in fluid, there is no need for a specific feature. The news are rendered in a for-loop, which provides a variable with the current index - use that (mod your number of templates) to render news differently. An example can be found here (Under the headline "Iteration information"): http://fluidtypo3.org/viewhelpers/fluid/master/ForViewHelper.html – Jost Oct 03 '14 at 14:18
  • @ Jost: Since this is the answer, why don't you post it as an answer and add information about the modulo usage (``)? – lorenz Oct 05 '14 at 20:55
  • @lorenz Since I'm lazy :-) – Jost Oct 06 '14 at 18:49

1 Answers1

2

Ok, again as answer:

You can just do this in fluid, there is no need for a specific feature. The news are rendered in a for-loop, which provides a variable with the current index, see the documentation.

Use the loop index modulo your number of different templates to render news differently in an alternating way. The iteration-variable provides some more subproperties that you can use for controlling the output. To see them all, use <f:debug>{iterator}</f:debug>.

For example, in the list-view of EXT:news you can do this to get three alternating templates, each one represented by a partial. Only the relevant inner loop is shown:

<f:for each="{news}" as="newsItem" iteration="iterator">
    <f:if condition="{iterator.index} % 3 == 0">
        <f:render partial="List/Item_Layout1" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
    </f:if>

    <f:if condition="{iterator.index} % 3 == 1">
        <f:render partial="List/Item_Layout2" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
    </f:if>

    <f:if condition="{iterator.index} % 3 == 2">
        <f:render partial="List/Item_Layout3" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
    </f:if>
</f:for>

If you have EXT:vhs installed with namespace shortcut v (very good extension!), this can be done a bit more elegant:

<f:for each="{news}" as="newsItem" iteration="iterator">
    <v:switch value="{iterator.index} % 3">
        <v:case value="0" break="true">
            <f:render partial="List/Item_Layout1" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
        </v:case>

        <v:case value="1" break="true">
            <f:render partial="List/Item_Layout2" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
        </v:case>

        <v:case value="2" break="true">
            <f:render partial="List/Item_Layout3" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
        </v:case>
    </v:switch>
Jost
  • 5,948
  • 8
  • 42
  • 72