View previous topic :: View next topic |
Author |
Message |
omexlu Smarty Rookie
Joined: 13 Mar 2014 Posts: 27
|
Posted: Thu Apr 21, 2016 5:05 pm Post subject: Random ausgabe im TPL |
|
|
Guten Tag,
Wie kann ich zB im Template folgendes realisieren
Code: | {RANDOM DIESE}
FOREACH-SCHLEIFE1
{ODER DIESE}
FOREARCH-SCHLEIFE2
{RANDOM CLOSE} |
Also ich hoffe ihr versteht was ich meine ich will Random endweder SCHLEIFE1 ODER SCHLEIFE2 ausführen?
Wie man ich das am besten?
Danke |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Apr 21, 2016 5:21 pm Post subject: |
|
|
It is best to NOT include random stuff into template.
If you have a number of blocks that you want to change on a page, use different cache_id for page that will be passed down to blocks and you can render content based on this cache_id. |
|
Back to top |
|
omexlu Smarty Rookie
Joined: 13 Mar 2014 Posts: 27
|
Posted: Thu Apr 21, 2016 5:26 pm Post subject: |
|
|
Thanks for you reply but i need this on my template for a dynamic change of something random.
Its possible? |
|
Back to top |
|
elpmis Smarty Elite
Joined: 07 Jun 2007 Posts: 321
|
Posted: Thu Apr 21, 2016 6:44 pm Post subject: |
|
|
What should be done inside the loop? |
|
Back to top |
|
omexlu Smarty Rookie
Joined: 13 Mar 2014 Posts: 27
|
Posted: Thu Apr 21, 2016 6:57 pm Post subject: |
|
|
elpmis wrote: | What should be done inside the loop? |
Hi,
I want to display two different foreach-loops who display different infos that comes from mySQL (differrent tables).
And now i want that it displayes one of the two loops per random
Code: | {RANDOM}
{foreach $rowsStrainImage as $rowStrainImage}
{$rowStrainImage.image}
{/foreach}
{ELSE}
{foreach $rowsMessageText as $rowMessageText}
{$rowMessageText.lang}
{/foreach}
{RANDOM CLOSE} |
Short example but i dont know how to random foreach-1 OR foreach-2. |
|
Back to top |
|
elpmis Smarty Elite
Joined: 07 Jun 2007 Posts: 321
|
Posted: Thu Apr 21, 2016 7:29 pm Post subject: |
|
|
Do you mean something like this?
Code: | {$rand = array_rand(array(1,2))}
{if $rand[0] == '1'}
{foreach $rowsStrainImage as $rowStrainImage}
{$rowStrainImage.image}
{/foreach}
{else}
{foreach $rowsMessageText as $rowMessageText}
{$rowMessageText.lang}
{/foreach}
{/if} |
Not approved ...
Last edited by elpmis on Tue Apr 26, 2016 8:14 am; edited 3 times in total |
|
Back to top |
|
omexlu Smarty Rookie
Joined: 13 Mar 2014 Posts: 27
|
Posted: Thu Apr 21, 2016 7:36 pm Post subject: |
|
|
I dont have i testet now but if seems to be this after i looked the code i give it a try tomorror
Thanks a lot. |
|
Back to top |
|
omexlu Smarty Rookie
Joined: 13 Mar 2014 Posts: 27
|
Posted: Fri Apr 22, 2016 9:20 am Post subject: |
|
|
Hi,
Unfortantly your version dont work but i have found a way todo this:
Code: |
{assign var='randomKey' value=1|rand:2}
{if $randomKey == "1"}
DOSOMETHING
{else}
DOSOMETHING-ELSE
{/if} |
And NO is not because of you incorrect {/if} on last line
Thanks a lot |
|
Back to top |
|
|