我在下面的代码中将产品图片加载到Prestashop的产品页面的长描述中,它很适合将所有产品图像加载到彼此之下,我想在每两个图像之后添加一个“徽标”分隔符,下面是示例图片
{foreach from=$product.images item=image}
<li>
<img
src="{$image.bySize.thickbox_default.url}"
alt="{$image.legend}"
title="{$image.legend}"
width="100%"
itemprop="image"
>
</li>
{/foreach}
是的,可以通过在循环中添加if
条件在每个产品图像后添加徽标,如下所示:
{foreach from=$product.images item=image name=product_image}
<li>
<img
src="{$image.bySize.thickbox_default.url}"
alt="{$image.legend}"
title="{$image.legend}"
width="100%"
itemprop="image"
>
</li>
{if $smarty.foreach.product_image.index % 2 === 1}
<img class="logo" src="/img/logo-separator.png" />
{/if}
{/foreach}
首先,只需在产品图像的name=product_image
循环上添加foreach
,通过使用smarty
获取每个图像的索引,然后检查foreach
项目的索引,并在每隔一个图像后添加$smarty.foreach.product_image.index % 2 === 1
的徽标