Bonjour à tous.
J'ai un array contenant un listing de produit.
Avec Smarty
Je met en forme la page contenant
- un produit aléatoire mis en avant
- le listing global.
Pour cela, j'ai tire un nombre aléatoire inférieur au nombre total.
Je fais un premier foreach jusqu'a ce nombre aléatoire, puis je sort de la premier boucle.
Puis je reparcourt le boucle complete.
Je pense que vous imagiener le problème.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 {math equation=rand(1,count($products)) assign='myRandValue'} {if isset($products)} {foreach from=$products item=product name=products} {if ($smarty.foreach.products.iteration==$myRandValue)} <div id="best_prod" class="ajax_block_product item"> [... ] </div> {break} {/if} {/foreach} <ul id="product_list"> {foreach from=$products item=product name=products} <li class="ajax_block_product"> [...] </li> {/foreach} </ul> {/if}
C'est pas du tout optimiser car on parcourt ainsi deux fois la chaine.
Sans toucher à l'array de base voyez vous un meilleur conception?
Partager