Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
  #1  
Old 06-02-2006, 05:16 PM
libertate's Avatar
libertate libertate is offline
 
Join Date: Feb 2005
Location: Kiribati
Posts: 107
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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>
How can I make code A and code B alternate, or randomly displayed, using only template script?

Thanks!
Reply With Quote
  #2  
Old 06-04-2006, 07:43 PM
libertate's Avatar
libertate libertate is offline
 
Join Date: Feb 2005
Location: Kiribati
Posts: 107
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

bump, any ideas?
Reply With Quote
  #3  
Old 06-04-2006, 08:35 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
$num rand(01); 
Code:
<if condition="$num">Code A<else />Code B</if>
With a little more information I'll show you how to do what you want...
Reply With Quote
  #4  
Old 06-05-2006, 01:11 AM
libertate's Avatar
libertate libertate is offline
 
Join Date: Feb 2005
Location: Kiribati
Posts: 107
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 06-05-2006, 01:25 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>
Otherwise I would do this:
Code:
<if condition="exec_switch_bg() == 'alt1'">Code A<else />Code B</if>
Every time my second example executes, it will alternate.
Reply With Quote
  #6  
Old 06-05-2006, 04:35 PM
libertate's Avatar
libertate libertate is offline
 
Join Date: Feb 2005
Location: Kiribati
Posts: 107
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>
Or DIV (integer division)?
Code:
 <if "TIMENOW DIV 2"="TIMENOW % 2">Code A<else />Code B</if>
Reply With Quote
  #7  
Old 06-05-2006, 05:01 PM
Hellcat Hellcat is offline
 
Join Date: May 2003
Location: Germany
Posts: 560
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try this:

Code:
<if condition="$myalternate == 1">
  ... code A ...
  <if condition="$myalternate = 0"></if>
<else />
  ... code B ...
  <if condition="$myalternate = 1"></if>
</if>
Note that there are only SINGLE equal signs ("... = ...") in the secondary IFs and the usual double ones ("... == ...") in the first one.


[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....
Reply With Quote
  #8  
Old 06-06-2006, 02:16 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>
Note that the <else /> is optional.

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?
Reply With Quote
  #9  
Old 06-07-2006, 12:17 AM
libertate's Avatar
libertate libertate is offline
 
Join Date: Feb 2005
Location: Kiribati
Posts: 107
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hah! It worked. Thank you all!

Code:
<if condition="TIMENOW % 2">Code A<else />Code B</if>
The above works.

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
Reply With Quote
  #10  
Old 06-07-2006, 12:23 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:07 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06409 seconds
  • Memory Usage 2,256KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (9)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete