Last Updated: February 25, 2016
·
711
· cdw9

TAL code for making rows

Use case: you can repeat over items no problem, but how do you split it up into rows? Closing tags don't allow conditions. You can insert the wrapping row tags using the code below. This example splits the items up intro three per row.

<tal:thumbs repeat="item items">
    <tal:num define="num repeat/item/number;
                     end repeat/item/end">
        <tal:open condition="python:num % 3 == 1"
                  content="structure string:&lt;div class='row'&gt;" />
            <img tal:attributes="src item/absolute_url;
                                 alt item/Title"/>
        <tal:close condition="python:(num % 3 == 0) or end"
                   content="structure string:&lt;/div&gt;" />
    </tal:num>
</tal:thumbs>