PDA

View Full Version : Choose 1 of 3 alternatives


Jon12345
01-25-2013, 11:01 AM
I have 3 bits of code, but I only want to run one at any one time. So, I figured I could do something like this:

choice=2

If choice=1 then
<run this code>

Else If choice=2 then
<run this code>

Else If choice=3 then
<run this code>

End If

I would just change the value assigned to the choice variable.

I can do this in visual basic but not sure how to do it in a vbulletin template. Any help from someone here?

I know I would have to login and edit the template each time I wanted to alter which bit of code ran. Is there any easier way that could avoid this time sapping login and search for template?

Thanks,

Jon

kh99
01-25-2013, 12:07 PM
In vb templates you can do this:
<if condition="$choice == 1">
Choice 1
<else /><if condition="$choice == 2">
Choice 2
<else /><if condition="$choice == 3">
Choice 3
</if></if></if>



But what you can't really do is assign a value to $choice. Well, OK, you can but it's cheating. If you do this:
<if condition="$choice = 2"></if>


It has no effect on the template output but has a side effect of assigning the value.


As far as getting around the logging in an searching - maybe the easiest thing to do would be to create an admincp option for it. If you put your forum in debug mode (if you're not familiar with that, this article might be useful: www.vbulletin.org/forum/showthread.php?t=265999), then some links will appear on the admincp options pages that let you add new option groups and options (the link actually says "Add Setting"). If you create a new option with varname "my_choice" for example, then your template code can check the value by using $vboptions['my_choice'].

Jon12345
01-29-2013, 11:45 AM
Thank you for that rather excellent reply. :) I am hopeful this might provide the solution I seek. I test different ad networks and often have to switch between them. Its a pain having to keep adding and deleting <!-- ---> all the time.