Loop lists can be used to construct arbitrary lists based on the contents of a database field, a search or other value (like a fixed list). Loop accepts a search parameter that will do one-click searches on a database table (or file).
To iterate over all keys in a table, use the idiom ([loop search="ra=yes/ml=9999"] [/loop]. ra=yes sets mv_return_all, which means "match everything". ml=9999 limits matches to that many records. If the text file for searching an Interchange DBM database is not used, set st=db (mv_searchtype).
When using st=db, returned keys may be affected by TableRestrict. Both can be sorted with [sort table:field:mod -start +number] modifiers. See sorting.
The Interchange Tags Reference has more information on the [loop] tag.
[loop item item item] LIST [/loop]
named attributes: [loop prefix=label* list="item item item"* search="se=whatever"*]
Returns a string consisting of the LIST, repeated for every item in a comma-separated or space-separated list. This tag works the same way as the [item-list] tag, except for order-item-specific values. It is intended to pull multiple attributes from an item modifier, but can be useful for other things, like building a pre-ordained product list on a page.
Loop lists can be nested by using different prefixes:
[loop prefix=size list="Small Medium Large"] [loop prefix=color list="Red White Blue"] [color-code]-[size-code]<BR> [/loop] <P> [/loop]
This will output:
Red-Small White-Small Blue-Small Red-Medium White-Medium Blue-Medium Red-Large White-Large Blue-Large
The search="args" parameter will return an arbitrary search, just as in a one-click search:
[loop search="se=Americana/sf=category"] [loop-code] [loop-field title] [/loop]
The above will show all items with a category containing the whole world "Americana."
[if-loop-data table field] IF [else] ELSE [/else][/if-loop-data]
Outputs the IF if the field in the table is not empty or the ELSE (if any) otherwise.
Note: This tag does not nest with other if-loop-data tags.
[if-loop-field] IF [else] ELSE [/else][/if-loop-field]
Outputs the IF if the field in the products table is not empty or the ELSE (if any) otherwise.
Note: This tag does not nest with other if-loop-field tags.
[loop-alternate N] DIVISIBLE [else] NOT DIVISIBLE [/else][/loop-alternate]
Set up an alternation sequence. If the loop-increment is divisible by N, the text will be displayed. If [else]NOT DIVISIBLE TEXT [/else] is present, then the NOT DIVISIBLE TEXT will be displayed. For example:
[loop-alternate 2]EVEN[else]ODD[/else][/loop-alternate] [loop-alternate 3]BY 3[else]NOT by 3[/else][/loop-alternate]
Terminates the alternation area.
Same as [item-change], but within loop lists.
Evaluates to the first returned parameter for the current returned record.
[loop-data database fieldname]
Evaluates to the field name fieldname in the arbitrary database table database for the current item.
Evaluates to the product description for the current item. Returns the <Description Field> from the first products database where that item exists.
The [loop-field] tag is special in that it looks in any of the tables defined as ProductFiles, in that order, for the data and returns the value only if that key is defined. In most catalogs, where ProductFiles is not defined [loop-field title] is equivalent to [loop-field products title].
Evaluates to the field name fieldname in the database for the current item.
Evaluates to the number of the item in the list. Used for numbering items in the list. Starts from one (1).
Evaluates the output of the ITL tags encased in the [loop-last] tags. If it evaluates to a numerical non-zero number (for example, 1, 23, -10 etc.), the loop iteration will terminate. If the evaluated number is negative, the item itself will be skipped. If the evaluated number is positive, the item itself will be shown, but will be last on the list.
[loop-last][calc] return -1 if '[loop-field weight]' eq ''; return 1 if '[loop-field weight]' < 1; return 0; [/calc][/loop-last]
If this is contained in your [loop list] and the weight field is empty, a numerical -1 will be output from the [calc][/calc] tags; the list will end and the item will not be shown. If the product's weight field is less than 1, a numerical 1 is output. The item will be shown, but it will be the last item on the list.
Evaluates the output of the ITL tags encased in the [loop-next] tags. If it evaluates to a numerical non-zero number (for example, 1, 23, -10 etc.), the loop will be skipped with no output. Example:
[loop-next][calc][loop-field weight] < 1[/calc][/loop-next]
If this is contained in your [loop list] and the product's weight field is less than 1, a numerical 1 will be output from the [calc][/calc] operation. The item will not be shown.
[loop-price n* noformat*]
Evaluates to the price for the optional quantity n (from the products file) of the current item, with currency formatting. If the optional "noformat" is set, then currency formatting will not be applied.
[loop-calc] PERL [/loop-calc]
Calls embedded Perl with the code in the container. All [loop-*] tags can be placed inside except for [loop-filter ...][/loop-filter], [loop-exec routine][/loop-exec], [loop-last][/loop-last] and [loop-next][/loop-next].
Note: All normal embedded Perl operations can be used, but be careful to pre-open any database tables with a [perl tables="tables you need"][/perl] tag prior to the opening of the [loop].
Calls a subroutine predefined either in catalog.cfg with Sub or in a [loop] with [loop-sub routine] PERL [/loop-sub]. The container text is passed as $_ and the array (or hash) value of the current row is $_.
Defines a subroutine that is available to the current (and subsequent) [loop-*] tags within the same page. See Interchange Programming.