Jump to content

Rendre un affichage aléatoire


Recommended Posts

Bonjour est il possible de rendre un affichage aléatoire directement dans le fichier tpl ?

C'est un block afficher sur la page index que nous utilisons comme testimonial.

 

Je vous met le code du fichier ci dessous, Merci d'avance.

 

{if $page.page_name=='index'}
<div class="anthemeblocks-reviews owl-carousel owl-theme{if $an_staticblock->formdata && $an_staticblock->formdata->additional_field_reviews_mobile=='0'}  anthemeblocks-reviews-hide-mobile{/if}" id="anthemeblocks-reviews_{$an_staticblock->id}" {if $an_staticblock->getImageLink() != ''}style="background-image: url({$an_staticblock->getImageLink()});"{/if}style="background-color: transparent;" style="border:2px dashed #000000;" {if $an_staticblock->formdata} data-nav="{$an_staticblock->formdata->additional_field_reviews_nav}" data-dots="{$an_staticblock->formdata->additional_field_reviews_dots}" data-loop="{$an_staticblock->formdata->additional_field_reviews_loop}"   data-autoplay="{$an_staticblock->formdata->additional_field_reviews_autoplay}" data-autoplaytimeout="{$an_staticblock->formdata->additional_field_reviews_autoplayTimeout}"{/if}>
{foreach from=$an_staticblock->getChildrenBlocks() item=block}
	<div class="item container" style="border:2px dashed #000000;"> <h2 style="text-align: center;"><strong>TESTIMONIAL</strong></h2>
		{$block->getContent() nofilter}
	</div>
{/foreach}
</div>
{/if}

 

Link to comment
Share on other sites

Just now, Postel nicolas said:

donc j'inclus ce code à l'intérieur du "foreach" ?

 

non

{if $page.page_name=='index'}
{math equation="rand(min, max)" min="1" max="3" assign="num"}
{if $num ==3}
<div class="anthemeblocks-reviews owl-carousel owl-theme{if $an_staticblock->formdata && $an_staticblock->formdata->additional_field_reviews_mobile=='0'}  anthemeblocks-reviews-hide-mobile{/if}" id="anthemeblocks-reviews_{$an_staticblock->id}" {if $an_staticblock->getImageLink() != ''}style="background-image: url({$an_staticblock->getImageLink()});"{/if}style="background-color: transparent;" style="border:2px dashed #000000;" {if $an_staticblock->formdata} data-nav="{$an_staticblock->formdata->additional_field_reviews_nav}" data-dots="{$an_staticblock->formdata->additional_field_reviews_dots}" data-loop="{$an_staticblock->formdata->additional_field_reviews_loop}"   data-autoplay="{$an_staticblock->formdata->additional_field_reviews_autoplay}" data-autoplaytimeout="{$an_staticblock->formdata->additional_field_reviews_autoplayTimeout}"{/if}>
{foreach from=$an_staticblock->getChildrenBlocks() item=block}
	<div class="item container" style="border:2px dashed #000000;"> <h2 style="text-align: center;"><strong>TESTIMONIAL</strong></h2>
		{$block->getContent() nofilter}
	</div>
{/foreach}
</div>
{/if}
{/if}

voila le code,

cdt

Link to comment
Share on other sites

Ok

 

Je viens de faire comme ceci

{if $page.page_name=='index'}
<div class="anthemeblocks-reviews owl-carousel owl-theme{if $an_staticblock->formdata && $an_staticblock->formdata->additional_field_reviews_mobile=='0'}  anthemeblocks-reviews-hide-mobile{/if}" id="anthemeblocks-reviews_{$an_staticblock->id}" {if $an_staticblock->getImageLink() != ''}style="background-image: url({$an_staticblock->getImageLink()});"{/if}style="background-color: transparent;" style="border:2px dashed #000000;" {if $an_staticblock->formdata} data-nav="{$an_staticblock->formdata->additional_field_reviews_nav}" data-dots="{$an_staticblock->formdata->additional_field_reviews_dots}" data-loop="{$an_staticblock->formdata->additional_field_reviews_loop}"   data-autoplay="{$an_staticblock->formdata->additional_field_reviews_autoplay}" data-autoplaytimeout="{$an_staticblock->formdata->additional_field_reviews_autoplayTimeout}"{/if}>
{foreach from=$an_staticblock->getChildrenBlocks() item=block}
	
	{math equation="rand(min, max)" min="1" max="3" assign="num"}
{if $num ==3}
<div class="item container" style="border:2px dashed #000000;"> <h2 style="text-align: center;"><strong>TESTIMONIAL</strong></h2>
		{$block->getContent() nofilter}
	</div>
{/if}
	
	
{/foreach}
</div>
{/if}

Et cela fonctionne aussi apparemment

Mais j'ai mis votre code.

 

par contre pour le moment nous n'avons pas beaucoup de données du coup comment éviter que le bloc n'affiche rien ?

à la place de la condition  {if $num ==3} il n'y a pas moyen de classer du plus petit au plus grand ou l'inverse cela pourrait garantir l'affiche de 100% des données mais en aléatoire selon comment la variable {math equation="rand(min, max)" min="1" max="3" assign="num"} atribue le numéro, le tout en allongeant la donnée max à un nombre plus grand.

Link to comment
Share on other sites

17 minutes ago, Alexandre Carette said:

excuse moi mais j'ai rien compris apres tu peux mettre des opérateurs style {if $num >2} {if $num <=1} etc...

cdt

désolé je vais essayer d'être plus clair

Si dans {math equation="rand(min, max)" min="1" max="3" assign="num"} je max à max="100" toutes mes données aurons un chiffre attribuer aléatoirement de 1 à 100

A la place de {if $num ==3} il n'y aurait pas un operateur permettant de les afficher mais une fois reclasser par ordre croissant ou décroissant ?

Comme cela, tous les blocks pourront s'afficher mais dans un ordre aléatoire (ces blocs sont afficher sous forme de slider)

 

 

10 minutes ago, Alexandre Carette said:

ah je viens de comprendre en fait tu a plusieurs blocs , il faut que tu regardes la fonction getChildrenBlocks et il ne faut pas boucler, faut faire la modif directement en php au niveau de la requete SQL,

cdt

en faite j'ai regarder un peu la structure du module et je ne peut pas faire comme cela car avec la fonction getChildrenBlocks il n'i a pas que ces block de générer mais tout un ensemble de block

 

image.thumb.png.8cc7d62c4dbaf6c308c5e87f5d633e7a.png

Edited by Postel nicolas (see edit history)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...