Loops with iterators


The operator corresponding with this action looks like the following:

<TMPL_foreach CYCLE_NAME as ITERATOR_NAME>
     <TMPL_var ITERATOR_NAME.VAR_NAME> <TMPL_var VAR_NAME>.
</TMPL_foreach>

All variables, which are contained in the current iteration in any levels of nesting, are accessible as the elements of iterator, assigned through the point.
If the name of iterator indicated, variable searches for first inside iterator, and then - in the global region of the data, just as in TMPL_loop. Thus, in our example <TMPL_var ITERATOR_NAME.VARIABLE_NAME> and <TMPL_var VARIABLE_NAME> will give out one and the same result.

The use of iterators usefully when inside the inserted loops is required to derive variables from the external cycles.
<TMPL_foreach pages as page>
    <TMPL_foreach page.users as user>
        <TMPL_foreach user.friends as friend>
            Page:   <TMPL_var page.id> <TMPL_var page.url>
            User:   <TMPL_var user.id> <TMPL_var user.name>
            Friend: <TMPL_var friend.id> <TMPL_var friend.name>
        </TMPL_foreach>
    </TMPL_foreach>
</TMPL_foreach>


In other cases using of <TMPL_foreach> is completely analogous <TMPL_loop>.

Copyright © 2003 - 2010 CTPP Dev. Team | http://ctpp.havoc.ru