Search code examples
phphtmlprestashopsmarty

Include a static html image in a dynamic database loading code


I have the below code which will load product pictures in the product page's long description in Prestashop, it works great to load all the product images below each other,I would like to add a little "logo" separator after every two images, below an example image

{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}  

enter image description here


Solution

  • Yes it is possible to add a logo after each product image by adding if condition within the loop as you can see below:

    {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} 
    

    First of all, just add name=product_image on foreach loop of product images to get the indices of each image by using smarty then check the index of foreach items and after every second image just add a logo by $smarty.foreach.product_image.index % 2 === 1