I am trying to create a template that will put items in a table.
Controller:
items = Item.all().order('name').fetch(10)
template_values = {'items': items,
'headers': ['Name', 'Price', 'Quantity']}
render('Views/table.html', self, template_values)
Template:
<table>
<tr>
{% for header in headers %}
<th>{{header}}</th>
{% endfor %}
</tr>
{% for item in items %}
<tr><td><a href="detail/{{item.CSIN}}">{{item.name}}</a></td><td>{{item.CSIN}}</td></tr>
{% endfor %}
</table>
Right now, the template is hard coded to look for certain attributes of item
. I want to change this so it either looks for the attributes with the names that are in headers
, or so that it looks for the first n attributes, where n is the length of headers
.
How can I do this?