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.
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