0

I'm using Typo3 6.0 and News System 2.0. I have a custom template using fluid viewhelpers, and I'm displaying news from my database depending on their categories. So far so good, no problem.

My problem is that I want to loop through all the news records (which are in the table tx_news_domain_model_news) so I can use conditions to filter which ones are displayed, but so far it seems my attempts were in vain.

Why is it possible to loop through news categories like this :

<f:for each="{newsItem.categories}" as="category">
     <f:if condition="{category.uid} == 9">
           {category.title} #this is displayed correctly.
     </f:if>
</f:for>

but when I try to loop through newsItem.uid, it's not working?

<f:for each="{newsItem.uid}" as="pub">
        <f:if condition="{pub} == 5">
             {pub.title}
        </f:if>
</f:for>

Thank you for your time.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
user2179985
  • 75
  • 3
  • 10
  • A news item only has one uid, so why are you looping through it? And also, what are you trying to achieve with all this? – Shufla Jun 20 '13 at 20:32
  • @Shufla Well I'm trying to loop with a custom field, which is a number, so I can compare it with another. It seems I wasn't able to loop with my custom field, it just didn't work, so I was trying another way using the uid thinking I could use that to access my custom field, but I guess I don't fully understand the ForViewHelper with News... What can I do ? – user2179985 Jun 21 '13 at 01:40

1 Answers1

1

You messed things a little (actually @Shufla told that yet).

for each statement in all languages allows you to iterate through some kind of collection. In this case every newsItem can have some categories connected, so you can for each item iterate through its categories (which are objects). In pseudo code it something like:

<f:for each="[cat1,cat2,cat3]" as="currentObject">
    {currentObject.property}
</f:for>

UID in TYPO3 is always an integer and is unique so there is not possible to iterate through it, cause pseudo code looks like that (must fail):

<f:for each="1" as="currentObject">
    {currentObject.property}
</f:for>

I don't know news' view however i just assume that this will work:

<f:for each="{news}" as="pub">
        <f:if condition="{pub.uid} == 5">
             {pub.title}
        </f:if>
</f:for>

However make sure that you don't perform - nested iteration again, maybe you have all you need in default view's iteration yet?

Edit

as you can see newsItem is passed to List/Item partial from iteration in News/List.html view (in folder Templates) so you are not able to repeat this iteration in the partial as you have there only ONE news obj available.

If you want/need to make some conditional iteration do it in view: /typo3conf/ext/news/Resources/Private/Templates/News/List.html

biesior
  • 55,576
  • 10
  • 125
  • 182
  • Thanks for your answer. Apparently I was a bit messed up. Anyways, what I don't understand is that what you justed posted : {pub.title} should be working right ? But in my case it's not working, and I do have a news in my tx_news_domain_model_news table with uid 5. So far, it only worked when I tried to loop over categories. Do you know why ? and what else can I do if I want to loop over my news records ? – user2179985 Jun 21 '13 at 13:42
  • I have already filtered the news I want to display the reason why I'm trying to loop over news in the template like this : settings < plugin.tx_news.settings settings { limit = 4 startingpoint = 30 categories = 8 }, but I need to put a special condition, so I thought I could loop over them in the template to do that, is it possible ? – user2179985 Jun 21 '13 at 13:51