Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Random ausgabe im TPL

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
omexlu
Smarty Rookie


Joined: 13 Mar 2014
Posts: 27

PostPosted: Thu Apr 21, 2016 5:05 pm    Post subject: Random ausgabe im TPL Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Apr 21, 2016 5:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
omexlu
Smarty Rookie


Joined: 13 Mar 2014
Posts: 27

PostPosted: Thu Apr 21, 2016 5:26 pm    Post subject: Reply with quote

Thanks for you reply but i need this on my template for a dynamic change of something random.

Its possible?
Back to top
View user's profile Send private message
elpmis
Smarty Elite


Joined: 07 Jun 2007
Posts: 321

PostPosted: Thu Apr 21, 2016 6:44 pm    Post subject: Reply with quote

What should be done inside the loop?
Back to top
View user's profile Send private message
omexlu
Smarty Rookie


Joined: 13 Mar 2014
Posts: 27

PostPosted: Thu Apr 21, 2016 6:57 pm    Post subject: Reply with quote

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 Smile

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
View user's profile Send private message
elpmis
Smarty Elite


Joined: 07 Jun 2007
Posts: 321

PostPosted: Thu Apr 21, 2016 7:29 pm    Post subject: Reply with quote

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
View user's profile Send private message
omexlu
Smarty Rookie


Joined: 13 Mar 2014
Posts: 27

PostPosted: Thu Apr 21, 2016 7:36 pm    Post subject: Reply with quote

I dont have i testet now but if seems to be this after i looked the code i give it a try tomorror Smile

Thanks a lot.
Back to top
View user's profile Send private message
omexlu
Smarty Rookie


Joined: 13 Mar 2014
Posts: 27

PostPosted: Fri Apr 22, 2016 9:20 am    Post subject: Reply with quote

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 Smile

Thanks a lot
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP