View Full Version : I need help with an IF conditional...
Ocean
09-01-2004, 06:38 PM
Okay, here's the scenario - I have a section of code in one of the PHP files that sets a variable to either true or false, for example:
if (blah blah blah)
{
$custom_variable = true;
}
else
{
$custom_variable = false;
}
Now, I want a section in one of the vB Templates to be able to pull from that so that if $custom_variable was set to true, than a section of code would execute (and if it's false, it would not) - for example:
<if condition="$custom_variable">
<!-- Insert Code to be executed here -->
</if>
However, the template portion of the code isn't working for me.
So the question is - what am I doing wrong? :rolleyes:
What you've done seems fine, but keep in mind you can't "execute" any code in the templates. It's plain html that goes there, besides the variables and the conditional system.
Ocean
09-01-2004, 10:34 PM
What you've done seems fine, but keep in mind you can't "execute" any code in the templates. It's plain html that goes there, besides the variables and the conditional system.
That's fine - the code that gets inserted there is standard Template-style code. The problem is that that code is being run, even though the template IF statement should be evaluating to false.
Is the problem that the variable in the PHP code needs to be defined or declared previously?
Because either there is a problem with that variable, or the template IF statement can't read it properly.
CarCdr
09-02-2004, 02:03 AM
What you've done seems fine, but keep in mind you can't "execute" any code in the templates. It's plain html that goes there, besides the variables and the conditional system.
While not really on subject for Ocean, I believe you can execute code in a template conditional. For example, the following should work:
<if condition="$FOO==1 AND $FOO = 2">
would set $FOO to 2 if it was equal to 1. I would bet one can hide any PHP one wanted in conditionals, with just a little trickery.
CarCdr,
i was referring to the "Insert Code to be executed here" part of his statement, which is between if tags.
Ocean, is the variable defined BEFORE the template is evaluated? Also, check it's value by just adding
echo $custom_variable; exit;
after the if.
nexialys
09-02-2004, 11:22 AM
work this out with the vB iif:
$custom_variable = iif('blah blah', 1);
with that, your $custom_variable will have a value, then be parsed within the <if condition="$custom_variable"></if>
Ocean
09-02-2004, 11:57 AM
Okay, problem solved. My original code should have worked just fine - the text editor I happened to use once added an additional hidden character to a Paste function, which effectively made it so that the variable being set in the PHP file was not the same variable being called by the template code.
I hate it when problems of this nature surface. Ai.
Thank you, everyone, for your help. :)
That's why notepad rocks. :D
Ocean
09-02-2004, 12:15 PM
That's why notepad rocks. :D
Actually, my usual Text Editor of choice is UltraEdit, and it makes Notepad look like a slab of rock with a hammer and chisel. :)
It's the one time I deviated from that, that I got burned. Well, that will be the last time that happens. :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.