vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Coding question (https://vborg.vbsupport.ru/showthread.php?t=115544)

Tim Skellett 05-14-2006 08:49 AM

Coding question
 
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:

Code:

<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

Code:

<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

Quote:

Originally Posted by Zachery
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!):

Code:

blah blah <if condition="$condition">Do this<else />Or Do This</if>blah blah
Code:

blah blah " . ($condition ? "Do This" : "Or Do This") . "blah blah
Example:
PHP Code:

<?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

Quote:

Originally Posted by SirAdrian
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!):

Code:

blah blah <if condition="$condition">Do this<else />Or Do This</if>blah blah
Code:

blah blah " . ($condition ? "Do This" : "Or Do This") . "blah blah
Example:
PHP Code:

<?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

Quote:

Originally Posted by Zachery
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. :)


All times are GMT. The time now is 03:50 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01205 seconds
  • Memory Usage 1,735KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_code_printable
  • (2)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete