3.4. loop

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]

            [loop prefix=size list="Small Medium Large"]
                [loop prefix=color list="Red White Blue"]
            [loop search="se=Americana/sf=category"]
                [loop-code] [loop-field title]

[if-loop-data table field] IF [else] ELSE [/else][/if-loop-data]

Note: This tag does not nest with other if-loop-data tags.

[if-loop-field] IF [else] ELSE [/else][/if-loop-field]

Note: This tag does not nest with other if-loop-field tags.

[loop-alternate N] DIVISIBLE [else] NOT DIVISIBLE [/else][/loop-alternate]

            [loop-alternate 2]EVEN[else]ODD[/else][/loop-alternate]
            [loop-alternate 3]BY 3[else]NOT by 3[/else][/loop-alternate]


[loop-change marker]


[loop-data database fieldname]


[loop-field fieldname]



                return -1 if '[loop-field weight]' eq '';
                return 1 if '[loop-field weight]' < 1;
                return 0;


              [loop-next][calc][loop-field weight] < 1[/calc][/loop-next]

[loop-price n* noformat*]

[loop-calc] PERL [/loop-calc]

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].

[loop-exec routine]argument[/loop-exec]

[loop-sub routine]PERL[/loop-sub]