Display all categories from news item

461 Views Asked by At

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

There are 1 best solutions below

0
On BEST ANSWER

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>