if — conditional parsing
Attribute | Pos. | Req. | Default | Description |
---|---|---|---|---|
type | Yes | |||
term | Yes | |||
op | Yes | |||
compare | Yes | |||
interpolate | 0 | interpolate input? | ||
reparse | 1 | interpolate output? | ||
hide | 0 | Hide the tag return value? |
Allows conditional parsing based upon the setting of various Interchange session and database values:
The Interchange configuration variables. These are set by the directives in your Interchange configuration file (or the defaults).
The Interchange database tables. Retrieves a column in the named table and returns true or false, based upon the value.
Check to see whether there are any error/information messages associated with a named form value.
[if errors fname] Please enter your first name. [/if]
A test for an explicit value. If Perl code is placed in a [condition] container then the supplied code will be used to make the comparison.
This is much like the data
test type, listed above, except that it works on the the table(s) listed in the DefaultTables
local configuration directive.
Usually used as a litmus test to see if anything is in the cart, for example: If no cart name is specified then "main" will be used.
Order status of individual items in the Interchange shopping carts. If no cart name is specified then "main" will be used.
Test a page Pragma
value, set with the the Pragma
directive in the catalog.cfg
file, or with the pragma
tag.
Test a scratchpad variables, previously set with [set]
, [seti]
, [tmp]
and [tmpn]
(or not set, as the case may be).
This is the same as the "scratch
" test type, except that the variable is deleted from the scratchpad after testing.
![]() |
Note |
---|---|
Introduced in version 5.5.1. |
Test for existence of non-session temporary value, set with either the [ts]
or [tn]
tags, or via $Tmp
in Perl.
![]() |
Note |
---|---|
Introduced in version 5.8.2. |
A special case which takes the form [if validcc no type exp_date]
. Evaluates to true if the supplied credit card number, type of card and expiration date pass a validity test. Does a LUHN-10 calculation to weed out typos or phony card numbers. Uses the standard CreditCardAuto
values for targets if nothing else is specified.
Interchange 5.9.0:
Source: lib/Vend/Interpolate.pm
Lines: 1467
sub tag_if { my ($cond,$body,$negate) = @_; #::logDebug("Called tag_if: $cond\n$body\n"); my ($base, $term, $op, $operator, $comp); my ($else, $elsif, $else_present, @addl); ($base, $term, $operator, $comp) = split /\s+/, $cond, 4; if ($base eq 'explicit') { $body =~ s#$QR{condition_begin}##o and ($comp = $1, $operator = ''); } #::logDebug("tag_if: base=$base term=$term op=$operator comp=$comp"); #Handle unless ($base =~ s/^\W+// or $base = "!$base") if $negate; $else_present = 1 if $body =~ /\[[EeTtAaOo][hHLlNnRr][SsEeDd\s]/; ($body, $elsif, $else, @addl) = split_if($body) if $else_present; #::logDebug("Additional ops found:\n" . join("\n", @addl) ) if @addl; unless(defined $operator) { undef $operator; undef $comp; } my $status = conditional ($base, $term, $operator, $comp, @addl); #::logDebug("Result of if: $status\n"); my $out; if($status) { $out = $body; } elsif ($elsif) { $else = '[else]' . $else . '[/else]' if length $else; my $pertinent = Vend::Parse::find_matching_end('elsif', \$elsif); unless(defined $pertinent) { $pertinent = $elsif; $elsif = ''; } $elsif .= '[/elsif]' if $elsif =~ /\S/; $out = '[if ' . $pertinent . $elsif . $else . '[/if]'; } elsif (length $else) { $out = $else; } return $out; } # This generates a *session-based* Autoload routine based # on the contents of a preset Profile (see the Profile directive). # # Normally used for setting pricing profiles with CommonAdjust, # ProductFiles, etc. # sub restore_profile { my $save; return unless $save = $Vend::Session->{Profile_save}; for(keys %$save) { $Vend::Cfg->{$_} = $save->{$_}; } return; } sub tag_profile { my($profile, $opt) = @_; #::logDebug("in tag_profile=$profile opt=" . uneval_it($opt)); $opt = {} if ! $opt; my $tag = $opt->{tag} || 'default'; if(! $profile) { if($opt->{restore}) { restore_profile(); if(ref $Vend::Session->{Autoload}) { @{$Vend::Session->{Autoload}} = grep $_ !~ /^$tag-/, @{$Vend::Session->{Autoload}}; } } return if ! ref $Vend::Session->{Autoload}; $opt->{joiner} = ' ' unless defined $opt->{joiner}; return join $opt->{joiner}, grep /^\w+-\w+$/, @{ $Vend::Session->{Autoload} }; } if($profile =~ s/(\w+)-//) { $opt->{tag} = $1; $opt->{run} = 1; } elsif (! $opt->{set} and ! $opt->{run}) { $opt->{set} = $opt->{run} = 1; } if( "$profile$tag" =~ /\W/ ) { logError( "profile: invalid characters (tag=%s profile=%s), must be [A-Za-z_]+", $tag, $profile, ); return $opt->{failure}; } if($opt->{run}) { #::logDebug("running profile=$profile tag=$tag"); my $prof = $Vend::Cfg->{Profile_repository}{$profile}; if (not $prof) { logError( "profile %s (%s) non-existant.", $profile, $tag ); return $opt->{failure}; } #::logDebug("found profile=$profile"); $Vend::Cfg->{Profile} = $prof; restore_profile(); #::logDebug("restored profile"); PROFSET: for my $one (keys %$prof) { #::logDebug("doing profile $one"); next unless defined $Vend::Cfg->{$one}; my $string; my $val = $prof->{$one}; if( ! ref $Vend::Cfg->{$one} ) { # Do nothing } elsif( ref($Vend::Cfg->{$one}) eq 'HASH') { if( ref($val) ne 'HASH') { $string = '{' . $prof->{$one} . '}' unless $prof->{$one} =~ /^{/ and $prof->{$one} =~ /}\s*$/; } } elsif( ref($Vend::Cfg->{$one}) eq 'ARRAY') { if( ref($val) ne 'ARRAY') { $string = '[' . $prof->{$one} . ']' unless $prof->{$one} =~ /^\[/ and $prof->{$one} =~ /]\s*$/; } } else { logError( "profile: cannot handle object of type %s.", $Vend::Cfg->{$one}, ); logError("profile: profile for $one not changed."); next; } #::logDebug("profile value=$val, string=$string"); undef $@; $val = $ready_safe->reval($string) if $string; if($@) { logError( "profile: bad object %s: %s", $one, $string ); next; } $Vend::Session->{Profile_save}{$one} = $Vend::Cfg->{$one} unless defined $Vend::Session->{Profile_save}{$one}; #::logDebug("set $one to value=$val, string=$string"); $Vend::Cfg->{$one} = $val; } return $opt->{success} unless $opt->{set}; } #::logDebug("setting profile=$profile tag=$tag"); my $al; if(! $Vend::Session->{Autoload}) { # Do nothing.... } elsif(ref $Vend::Session->{Autoload}) { $al = $Vend::Session->{Autoload}; } else { $al = [ $Vend::Session->{Autoload} ]; } if($al) { @$al = grep $_ !~ m{^$tag-\w+$}, @$al; } $al = [] if ! $al; push @$al, "$tag-$profile"; #::logDebug("profile=$profile Autoload=" . uneval_it($al)); $Vend::Session->{Autoload} = $al; return $opt->{success}; }