PREFIX-calc
Summary
- [PREFIX-calc] Perl code [/PREFIX-calc]
Description
Executes the Perl code given in the tag's body text.
This is equivalent to the [calc] tag,
except that it's calculated at loop time instead of later,
when the rest of the page is parsed.
The following example adds 2 to the current item's price
(see [PREFIX-price]),
and returns the result:
|
[PREFIX-calc] [PREFIX-price noformat] + 2 [/PREFIX-calc]
|
[PREFIX-calc] blocks may make use of a "$Row" hashref,
which contains the current row data.
The following demonstrates the use of the "$Row" hashref:
[item-calc]
if ($Row->{rip_off} eq 'Y') {
return $Row->{weight} + 10;
}
else {
return $Row->{weight};
}
[/item-calc]
|
|
Warning
No changes will be made to the underlying table data if you
make changes to the values in the "$Row" hashref.
|
|
Availability
The "$Row" hashref was introduced in version 5.3.2,
and is therefore not available for use in any earlier
Interchange version.
|
|
Note
The "$Row" hashref will be undefined when accessed within
Perl code contained in [perl],
[calc] and [calcn] tags etc. The "$Row" hashref is only valid in the context of a loop
([loop],
[query] and [item-list] tags etc.).
Also note that,
when used in a search-type loop (e.g. [loop search="..."]),
the return fields should be specified within the search in order for the
row hash to be populated correctly.
If this is not done then only the primary key will have a value in the
"$Row" hashref.
|