MyBB Hacks

Full Version: if string conditional
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
can we put some random code?

Code:
<if rand(1,2)>
$1 = {string1}
$2 = {string2}
</if>

it will be random,if not string 1 then string 2 will show up...

Code:
<if mt_rand(0,1) then>
string 1
<else>
string 2
</if>

how about more than 2 string?

Code:
<if mt_rand(0,2) then>
string 1
<elseif  mt_rand(0,2) then>
string 2
<elseif  mt_rand(0,2) then>
string 3
</if>


like that? but it doesn't work

Code:
<setvar r>array('text 1', 'text 2', 'text 3')</setvar>
<?=$GLOBALS['tplvars']['r'][array_rand($GLOBALS['tplvars']['r'])?>

<setvar r>array('text 1', 'text 2', 'text 3')</setvar>
<?=$GLOBALS['tplvars']['r'][array_rand($GLOBALS['tplvars']['r'])?>

don't work

i mean not text 1,2,3..but string like this

<setvar r>array('{string1}', '{string2}', '{string3}')</setvar>
<?=$GLOBALS['tplvars']['r'][array_rand($GLOBALS['tplvars']['r'])?>

i use this one but it doesn't work
(08-29-2012 07:08 PM)bekti Wrote: [ -> ]i mean not text 1,2,3..but string like this
Text 1, Text 2, Text 3 are strings.

Code:
<setvar r>array('{string1}', '{string2}', '{string3}')</setvar>
<?=$GLOBALS['tplvars']['r'][array_rand($GLOBALS['tplvars']['r'])?>



but when i try to set

Code:
<setvar r>array('{myadvertisements[zone_1]}', '{myadvertisements[zone_2]}', '{myadvertisements[zone_3]}')</setvar>
<?=$GLOBALS['tplvars']['r'][array_rand($GLOBALS['tplvars']['r'])?>



it's appear an error..my header template doesn't show up...

any fix?

This code works for me :

Code:
<setvar r>array('text 1', 'text 2', 'text 3')</setvar>
<?=$GLOBALS['tplvars']['r'][array_rand($GLOBALS['tplvars']['r'])]?>


I added a ] at the end of the second line right before the ?

(08-30-2012 01:36 AM)leefish Wrote: [ -> ]This code works for me :

Code:
<setvar r>array('text 1', 'text 2', 'text 3')</setvar>
<?=$GLOBALS['tplvars']['r'][array_rand($GLOBALS['tplvars']['r'])]?>


I added a ] at the end of the second line right before the ?


work like a charm...thank leefish
Reference URL's