typo3typo3-7.6.xtypo3-extensionstt-news

Display all categories from news item


I have a news item that has more categories. If I use firstCategory then I receive as output the first chosen category, but it’s not what I want. I want to display all the categories that a news item has been marked as. I've tried following but there is no output

<f:if condition=“{newsItem.categories}“>
    <span class=“news-list-category label label-default test”>
       <f:for each=“{categories}” as=“category”>
               {category.title}
       </f:for>
    </span>
</f:if>

Solution

  • In for loop use newsItem.categories instead of categories. Like below.

    <f:if condition=“{newsItem.categories}“>
        <span class=“news-list-category label label-default test”>
           <f:for each=“{newsItem.categories}” as=“category”>
                   {category.title}
           </f:for>
        </span>
    </f:if>