The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
random or flipping of section execution within template
Currently I have two sections within a template which gets executed depending on the pageid.
Code:
<if condition="($pages['pageid'] ==... ... code A ... <else /> ... code B ... </if> Thanks! |
#2
|
||||
|
||||
bump, any ideas?
|
#3
|
||||
|
||||
What are you trying to accomplish exactly? Will your template condition be executed more than once (in a loop), or just once? What would Code A and Code B contain?
If you want it random, have it generate a random number (say between 0 and 1), then in your template just check it. PHP Code:
Code:
<if condition="$num">Code A<else />Code B</if> |
#4
|
||||
|
||||
I want the code to be kept within the template and not use external code.
I simply one to display two javascripts. It would not loop. Depending on a random state, it should display one or the other. It doesn't even have to be random, it could be ABABABABA i.e. flipping Is there a template variable that changes at each load time? Time or or something else? Maybe then I can do a simple var div 2 != var / 2 to decide which section to execute. |
#5
|
||||
|
||||
If it is a one time per script thing, then I would do this:
Code:
<if condition="TIMENOW % 2">Code A<else />Code B</if> Code:
<if condition="exec_switch_bg() == 'alt1'">Code A<else />Code B</if> |
#6
|
||||
|
||||
Thank you!
Is there a round(), trunc(), ceiling(), floor() or similar function which I can use like this: Code:
<if round("TIMENOW % 2")="TIMENOW % 2">Code A<else />Code B</if> Code:
<if "TIMENOW DIV 2"="TIMENOW % 2">Code A<else />Code B</if> |
#7
|
|||
|
|||
Try this:
Code:
<if condition="$myalternate == 1"> ... code A ... <if condition="$myalternate = 0"></if> <else /> ... code B ... <if condition="$myalternate = 1"></if> </if> [EDIT] This may not work on the first try, depending on how the single bits are assembled (all in one function call, or each in seperate function call), so may want to find a variable with global scope you can use/hijack. For posts inside a thread, for example, you could use the $thread array ($thread[myalternate]) to keep your value between posts.... |
#8
|
||||
|
||||
Why not just use plugins to accomplish most of the processing, so you can keep the templates nice and simple?
@Hellcat: You really shouldn't use PHP like that in templates. Though it works, it defeats the whole purpose of the template system. Someone editing it will most likely remove the empty conditions and break the script without knowing what happened to it. @libertate: your syntax is a little off: Code:
<if condition="YOUR_CONDITION"> show this if YOUR_CONDITION is true <else /> Show this if YOUR_CONDITION is false. </if> Anyway, both of our examples do the same thing (alternate between true/false of the condition), so what exactly are you trying to accomplish here? |
#9
|
||||
|
||||
Hah! It worked. Thank you all!
Code:
<if condition="TIMENOW % 2">Code A<else />Code B</if> Coming from old school programming, I didn't realize that the "condition" was not a pseudonym, but the actual command, and the comparison was inside the quotes. :-/ So what does TIMENOW generate, and what does % mean? Is it MOD or something? Why is there no reference for this stuff (or so complicated to find / I looked on vB.com and couldn't find it)? If you wanted to know...Code A is Google Adsense, Code B is Yahoo Publisher Network. And it is showing positive impact to flip the advertisers periodically. :-D |
#10
|
||||
|
||||
TIMENOW is a Unix timestamp. % is mod, yes. The condition can basically be any PHP code, with the exception of only being able to run a few functions.
For more conditions you can use, you can just learn more PHP, but I think there are some basics in the vBulletin manual. |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|