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"]
                    [color-code]-[size-code]<BR>
                [/loop]
                <P>
            [/loop]
            Red-Small
            White-Small
            Blue-Small
        
            Red-Medium
            White-Medium
            Blue-Medium
        
            Red-Large
            White-Large
            Blue-Large
            [loop search="se=Americana/sf=category"]
                [loop-code] [loop-field title]
            [/loop]

[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-alternate]

[loop-change marker]

[loop-code]

[loop-data database fieldname]

[loop-description]

[loop-field fieldname]

[loop-increment]

[loop-last]tags[/loop-last]

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

[loop-next]tags[/loop-next]

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