Log in

View Full Version : Coding question


Tim Skellett
05-14-2006, 08:49 AM
Hi,
pardon this question (actually two); I'm a complete newbie when it comes to coding.

I would like to modify the following in a vB 3.5.4 template:

<if condition="$show['foo']">

and I would like to modify the above like so:

<if condition="$show['foo']" EXCEPT WHEN [if condition ="$A[X]" AND if condition"$[Y]"]>

or in other words do the operation as normal except when two other conditions are simultaneously met. How best do I code that?

Sorry if I sound painfully dumb; I am indeed a newbie.
______

That's the one question; my next question also refers to the above.
In the above, [Y] has a range of values, so I am looking at some kind of array, I suppose like so:

<if condition="$show['foo']" EXCEPT WHEN [if condition ="$A[X]" AND if condition"$[ARRAY(Y)]"]>

How best do I code that?

______

Many thanks in advance, and please pardon my ignorance.

It occurs to me it would be easier to do a nested "if" set, like so:

<if condition ="$A[X]" AND if condition"$[ARRAY(Y)]" AND if condition="$show"] show 'alternate'>
else
<if condition="$show['foo']" show 'foo'>
</if>
</if>

Is my coding above correct?

Many thanks in advance for help and patience.

Adrian Schneider
05-14-2006, 05:01 PM
<if condition="$show['foo'] and !$otherVarA and !$otherVarB">You can seperate multiple conditions with and, or, xor, etc. ! means NOT, so the above condition is true when [ $show['foo'] is true, $otherVarA is false and $otherVarB is false ]

Zachery
05-14-2006, 07:40 PM
Don't use single quotes inside of template conditional varibles.

use $show[foo] instead of $show['foo']

Adrian Schneider
05-14-2006, 08:29 PM
Don't use single quotes inside of template conditional varibles.


use $show[foo] instead of $show['foo']
That is silly and somewhat incorrect:

If foo is a constant, you will run into some problems that will probably take hours to solve. Remember that conditions are parsed like so (NOT in double quotes!):

blah blah <if condition="$condition">Do this<else />Or Do This</if>blah blah blah blah " . ($condition ? "Do This" : "Or Do This") . "blah blah Example: <?php

define('a', 'b');

$show['b'] = false;
$show['a'] = true;

echo ($show[a]) ? 'Working as expected' : 'Uh Oh!';

// outputs 'Uh Oh!'
?>

Zachery
05-15-2006, 05:15 AM
That is silly and somewhat incorrect:

If foo is a constant, you will run into some problems that will probably take hours to solve. Remember that conditions are parsed like so (NOT in double quotes!):

blah blah <if condition="$condition">Do this<else />Or Do This</if>blah blah blah blah " . ($condition ? "Do This" : "Or Do This") . "blah blah Example: <?php

define('a', 'b');

$show['b'] = false;
$show['a'] = true;

echo ($show[a]) ? 'Working as expected' : 'Uh Oh!';

// outputs 'Uh Oh!'
?>
I've always run into problems using single quotes inside of the varibles, and it goes away generally when I remove them.

Adrian Schneider
05-15-2006, 05:18 AM
I've always run into problems using single quotes inside of the varibles, and it goes away generally when I remove them.
Inside templates you can't use single quotes unless you wrap the variable in braces... In *conditions* though it is not parsed within double quotes. Hope that clears it up. :)