I usually try to put less logic in my views. For one, I try to assemble all 
the data fields ahead of time either in the controller or with virtual 
fields.

Then in the view, I try to just end up looping through the dict. I normally 
use HTML tags but using Web2py tag helpers should be fine as well.

See example below. Notice that I have a sliver of logic in there to display 
"no results" if there are no items. Also note that I have a couple fields 
like "item.last_date" that I have generated as a virtual field. In this way, 
you keep your views looking mostly like regular pages of HTML with some 
logic here and there.

    <table width="100%">
     <thead>
     <tr>
     <th></th>
     <th class="ttl">Description</th>
     <th class="prc">Current Price</th>
     <th class="prc">Final Price</th>
     </tr>
     </thead>
        <tbody>
        {{if len(items)==0:}}
            <tr><td colspan=4 align=middle><br>No items</td></tr>
        {{else:}}
            {{for item in items:}}
            <tr>
             <td>
             {{if len(item.image)==0:}}
                    {{=A(IMG(_src=URL('static','images/no-photo.png'), 
_width='80px'), _href=URL(c='default', f='item', extension='', args=item.id, 
))}}
                {{else:}}   
                    {{=A(IMG(_src=URL(c='default', f='download', 
args=item.image), _width='100px'), _href=URL(c='default', f='item', 
extension='', args=item.id))}} 
                {{pass}}
                </td>
             <td class="ttl">{{=A(item.title, _href=URL(c='default', 
f='item', extension='', args=item.id))}}</td>
             <td class="prc"><b>${{=item.current_price}}</b></td>
             <td class="prc">${{=item.last_price}} on 
{{=item.last_date}}</td>
            </tr>
            {{pass}}
        {{pass}}
        </tbody>
    </table>

Reply via email to