3. Looping tags and Sub-tags
Certain tags are not standalone; these are the ones that are interpreted as part of a surrounding looping tag like [loop], [item-list], [query], or [search-region].
-
[PREFIX-accessories]
[PREFIX-alternate]
[PREFIX-calc]
[PREFIX-change]
[PREFIX-code]
[PREFIX-data]
[PREFIX-description] (Note safe-data and ed() escape)
[PREFIX-discount]
[PREFIX-discount-subtotal]
[PREFIX-field] (Optimization note-- one query per field if you use this; we optimize around this if only one products table)
[PREFIX-increment]
[PREFIX-last]
[PREFIX-line] (tab-delimited list of parameters returned)
[PREFIX-modifier]
[PREFIX-next]
[PREFIX-param]
[PREFIX-pos]
[PREFIX-price]
[PREFIX-quantity]
[PREFIX-subtotal]
[if-PREFIX-data]
[if-PREFIX-field]
[if-PREFIX-param]
[if-PREFIX-pos]
[modifier-name]
[quantity-name]
PREFIX represents the prefix that is used in that looping tag. They are only interpreted within their container and only accept positional parameters. The default prefixes:
Tag | Prefix | Examples |
[loop] | loop | [loop-code], [loop-field price], [loop-increment] |
[item-list] | item | [item-code], [item-field price], [item-increment] |
[search-list] | item | [item-code], [item-field price], [item-increment] |
[query] | sql | [sql-code], [sql-field price], [sql-increment] |
Sub-tag behavior is consistent among the looping tags. Subtags are parsed during evaluation of the enclosing loop, before any regular tags within the loop.
There are two types of looping lists: ARRAY and HASH.
An array list is the normal output of a [query], a search, or a [loop] tag. It returns from 1 to N return fields, defined in the mv_return_fields or rf variable or implicitly by means of a SQL field list. The two queries below are essentially identical:
[query sql="select foo, bar from products"] [/query] [loop search=" ra=yes fi=products rf=foo,bar "]
Both will return an array of arrays consisting of the foo column and the bar column. The Perl data structure would look like:
[ ['foo0', 'bar0'], ['foo1', 'bar1'], ['foo2', 'bar2'], ['fooN', 'barN'], ]
A hash list is the normal output of the [item-list] tag. It returns the value of all return fields in an array of hashes. A normal [item-list] return might look like:
[ { code => '99-102', quantity => 1, size => 'XL', color => 'blue', mv_ib => 'products', }, { code => '00-341', quantity => 2, size => undef, color => undef, mv_ib => 'products', }, ]
You can also return hash lists in queries:
[query sql="select foo, bar from products" type=hashref] [/query]
Now the data structure will look like:
[ { foo => 'foo0', bar => 'bar0' }, { foo => 'foo1', bar => 'bar1' }, { foo => 'foo2', bar => 'bar2' }, { foo => 'fooN', bar => 'barN' }, ]