I have in a for each two condition. How can I clear the content? Don't need two content:
<f:for each="{newsItem.categories}" as="category">
<f:if condition="{category.uid} == 2">
<f:if condition="{newsItem.logo}">
Logo 1
</f:if>
</f:if>
<f:if condition="{category.uid} == 3">
<f:if condition="{newsItem.logo}">
Logo 1
</f:if>
</f:if>
</f:for>
I need one condition for 2 if´s In PHP I take a break? Thanks
You could use the ViewHelpers v:iterator.intersect
and v:iterator.extract
from the extension vhs
. It's not really elegant:
<f:if condition="{newsItem.categories -> v:iterator.extract(key: 'uid') -> iterator.intersect(b: '{0: 2, 1: 3}')}">
<f:if condition="{newsItem.logo}">
Logo 1
</f:if>
</f:if>
Alternatively, you could just write your own ViewHelper, which would be only a few lines of code.
You could also use the vhs if stack Viewhelper:
<v:if stack="{0: '{category.uid}', 1: '==', 2: '2', 3: 'OR', 4: '{category.uid}', 5: '==', 6: '3'}">
<f:then>
<f:if condition="{newsItem.logo}">
Logo 1
</f:if>
</f:then>
</v:if>
If you just want to avoid 2 similar blocks of HTML then you could use f:render and f:section:
<f:for each="{newsItem.categories}" as="category">
<f:if condition="{category.uid} == 2">
<f:render section="logo" arguments="{newsItem:newsItem}" />
</f:if>
<f:if condition="{category.uid} == 3">
<f:render section="logo" arguments="{newsItem:newsItem}" />
</f:if>
</f:for>
<f:section name="logo">
<f:if condition="{newsItem.logo}">
Logo 1
</f:if>
</f:section>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.