THIS TAG HAS SPECIAL POSITIONAL PARAMETER HANDLING.
Pass attribute hash as last to subroutine: no
Must pass named parameter interpolate=1 to cause interpolation.
This is a container tag, i.e. [if] FOO [/if]. Nesting: NO
Invalidates cache: YES
Called Routine:
Called Routine for positonal:
ASP/perl tag calls:
$Tag->if( { type => VALUE, term => VALUE, op => VALUE, compare => VALUE, }, BODY ) OR $Tag->if($type, $term, $op, $compare, $BODY);
Attribute aliases
base ==> type comp ==> compare condition ==> compare operator ==> op
Positional call example: [if type field op compare]
negated: [if type=``!type'' term=``field'' op=``op'' compare=``compare'']
Positional call example: [if !type field op compare]
Allows conditional building of HTML based on the setting of various MiniVend session and database values. The general form is:
[if type term op compare] [then] If true, this is printed on the document. The [then] [/then] is optional in most cases. If ! is prepended to the type setting, the sense is reversed and this will be output for a false condition. [/then] [elsif type term op compare] Optional, tested when if fails [/elsif] [else] Optional, printed when all above fail [/else] [/if]
The [if]
tag can also have some variants:
[if type=explicit compare=`$perl_code`] Displayed if valid Perl CODE returns a true value. [/if]
You can do some Perl-style regular expressions:
[if value name =~ /^mike/] This is the if with Mike. [elsif value name =~ /^sally/] This is an elsif with Sally. [/elsif] [elsif value name =~ /^pat/] This is an elsif with Pat. [/elsif] [else] This is the else, no name I know. [/else] [/if]
While named parameter tag syntax works for [if ...]
, it is more convenient to use positional calls in most cases. The only
exception is if you are planning on doing a test on the results of another
tag sequence: [if value name =~ /[value b_name]/] Shipping name matches
billing name. [/if]
Oops! This will not work. You must do instead
[if base=value field=name op="=~" compare="/[value b_name]/"] Shipping name matches billing name. [/if]
or better yet
[if type=explicit compare=` $Value->{name} =~ /$Value->{b_name}/ `] Shipping name matches billing name. [/if]
MiniVend also supports a limited [and ...] and [or ...] capability:
[if value name =~ /Mike/] [or value name =~ /Jean/] Your name is Mike or Jean. [/if]
[if value name =~ /Mike/] [and value state =~ /OH/] Your name is Mike and you live in Ohio. [/if]
If you wish to do very complex
AND and
OR operations, you will have to use
[if explicit]
or better yet embedded Perl/ASP. This allows complex testing and parsing of
values.
There are many test targets available:
[if config CreditCardAuto] Auto credit card validation is enabled. [/if]
[if data products::size::99-102] There is size information. [else] No size information. [/else] [/if]
[if data products::size::99-102 =~ /small/i] There is a small size available. [else] No small size available. [/else] [/if]
[if discount 99-102] Item is discounted. [/if]
[if explicit] [condition] $country = '[value country]'; return 1 if $country =~ /u\.?s\.?a?/i; return 0; [/condition] You have indicated a US address. [else] You have indicated a non-US address. [/else] [/if]
This example is a bit contrived, as the same thing could be accomplished with [if value country =~ /u\.?s\.?a?/i], but you will run into many situations where it is useful.
This will work for Variable values:
[if type=explicit compare="__MYVAR__"] .. [/if]
[if file /home/user/www/images/[item-code].gif] <IMG SRC="[item-code].gif"> [/if]
The file test requires that the SafeUntrap directive contains
ftfile
(which is the default).
[if items]You have items in your shopping cart.[/if] [if items layaway]You have items on layaway.[/if]
[if ordered 99-102] Item 99-102 is in your cart. [/if] Checks the status of an item on order, true if item 99-102 is in the main cart.
[if ordered 99-102 layaway] ... [/if] Checks the status of an item on order, true if item 99-102 is in the layaway cart.
[if ordered 99-102 main size] ... [/if] Checks the status of an item on order in the main cart, true if it has a size attribute.
[if ordered 99-102 main size =~ /large/i] ... [/if] Checks the status of an item on order in the main cart, true if it has a size attribute containing 'large'.
To make sure it is exactly large, you could use:
[if ordered 99-102 main size eq 'large'] ... [/if]
[if scratch mv_separate_items] ordered items will be placed on a separate line. [else] ordered items will be placed on the same line. [/else] [/if]
CreditCardAuto
variables for targets if nothing else is passed.
The field term is the specifier for that area. For example, [if session logged_in]
would return true if the logged_in
session parameter was set.
As an example, consider buttonbars for frame-based setups. It would be nice to display a different buttonbar (with no frame targets) for sessions that are not using frames:
[if scratch frames] __BUTTONBAR_FRAMES__ [else] __BUTTONBAR__ [/else] [/if]
Another example might be the when search matches are displayed. If you use the string '[value mv_match_count] titles found', it will display a plural for only one match. Use:
[if value mv_match_count != 1] [value mv_match_count] matches found. [else] Only one match was found. [/else] [/if]
The op term is the compare operation to be used. Compare operations are as in Perl:
== numeric equivalence eq string equivalence > numeric greater-than gt string greater-than < numeric less-than lt string less-than != numeric non-equivalence ne string equivalence
Any simple perl test can be used, including some limited regex matching.
More complex tests are best done with [if explicit]
.
Additional conditions for test, applied if the initial [if ..]
test fails.