Pioupial Posted November 15, 2019 Posted November 15, 2019 (edited) Prestashop : 1.7.6.1 Bonjour, Je souhaiterai afficher en bas de ma page produit les 2 premières images affectées à celui ci. L'idée est d'afficher chaque image dans une div côte à côte. Je parviens à afficher toutes les images de mon produit avec ce code ( soit 4 images), mais j'aimerai n'en afficher que 2. <div class="row mt-3 mb-3 text-md-center"> {foreach from=$product.images item=image} <div class="col-md-6 images-container"> <img data-image-large-src="{$image.large.url}" src="{$image.large.url}" alt="{$image.legend}" title="{$image.legend}" style="width:100%;" itemprop="image"> </div> {/foreach} </div> Merci pour votre aide Edited November 15, 2019 by Pioupial (see edit history) Share this post Link to post Share on other sites More sharing options...
lagui Posted November 15, 2019 Posted November 15, 2019 Bonjour, En ajoutant dans la boucle : {if [email protected] > 2} {break} {/if} Share this post Link to post Share on other sites More sharing options...
Pioupial Posted November 15, 2019 Posted November 15, 2019 Merci pour cette réponse rapide. J'ai fait ça, mais ça ne fonctionne pas, surement une erreur de ma part. <div class="row mt-3 mb-3 text-md-center"> {foreach from=$product.images item=image} {if [email protected] > 2} <div class="col-md-6 images-container"> <img data-image-large-src="{$image.large.url}" src="{$image.large.url}" alt="{$image.legend}" title="{$image.legend}" style="width:100%;" itemprop="image"> </div> {break} {/if} {/foreach} </div> Share this post Link to post Share on other sites More sharing options...
Pioupial Posted November 15, 2019 Posted November 15, 2019 En fait cela fonctionne mais ne m'affiche qu'une seule image, l'image numéro 3. Merci Share this post Link to post Share on other sites More sharing options...
lagui Posted November 15, 2019 Posted November 15, 2019 <div class="row mt-3 mb-3 text-md-center"> {foreach from=$product.images item=image} {if [email protected] > 2} {break} {/if} <div class="col-md-6 images-container"> <img data-image-large-src="{$image.large.url}" src="{$image.large.url}" alt="{$image.legend}" title="{$image.legend}" style="width:100%;" itemprop="image"> </div> {/foreach} </div> Share this post Link to post Share on other sites More sharing options...
lagui Posted November 15, 2019 Posted November 15, 2019 Juste le break dans le if pour sortir du foreach quand le nombre d'itération est atteint Share this post Link to post Share on other sites More sharing options...
Pioupial Posted November 15, 2019 Posted November 15, 2019 Parfait et merci pour l'explication. Merci beaucoup. Share this post Link to post Share on other sites More sharing options...
Pioupial Posted November 15, 2019 Posted November 15, 2019 Et si je souhaite afficher l'image n°1 et l'image n°3 quel sera le code ? Merci Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now