johndoe33
johndoe33

Reputation: 454

Vhs-viewhelper and for loop

I'm trying to get the next news item from within current news item. Using the extension "vhs" and tx_news.

{namespace v=FluidTYPO3\Vhs\ViewHelpers}
<f:for each="{news}" as="newsItem" iteration="iterator">
    Current title: {newsItem.title}
    <v:variable.set name="nextNews" value="{v:iterator.next(needle: newsItem, haystack: news)}"/>
    Next title: {nextNews.title}
</f:for>

It will print correct titles once. Then the loop ends abruptly.

Upvotes: 0

Views: 1003

Answers (2)

randomresult
randomresult

Reputation: 601

I had a problem yesterday with setting a variable in a for-loop. I solved the problem by clearing that variable. In your case i would try the following:

{namespace v=FluidTYPO3\Vhs\ViewHelpers}
<f:for each="{news}" as="newsItem" iteration="iterator">
<v:variable.set name="nextNews" value="" />
Current title: {newsItem.title}
<v:variable.set name="nextNews" value="{v:iterator.next(needle: newsItem, haystack: news)}"/>
Next title: {nextNews.title}
</f:for>

That one clears the variable before setting it (again). At least i would try that :)

Upvotes: 0

Ren&#233; Pflamm
Ren&#233; Pflamm

Reputation: 3354

I would try to set an condition to catch up the last iteration because there is no more "next" news.

{namespace v=FluidTYPO3\Vhs\ViewHelpers}
<f:for each="{news}" as="newsItem" iteration="iterator">
  Current title: {newsItem.title}
  <f:if condition="{iterator.isLast}">
    <f:else>
      <v:variable.set name="nextNews" value="{v:iterator.next(needle: newsItem, haystack: news)}"/>
      Next title: {nextNews.title}
    </f:else>
  </f:if>
</f:for>

Upvotes: 0

Related Questions