python-2.7turbogears2turbogears

How to print variable number of items using turbogears templates


Hello I've been tasked to work on a turbogears project not knowing anything about the webstack. :)

Anyways, I've been going through some turbogears tutorials and I had a question about printing a variable number of items in turbogears.

So, let's say I have a template printing cars a given owner may have. It will print year, make, model, and color. An owner may have 1-n cars.

The examples I found on line for printing one car are pretty straight forward: @expose a function that returns a dictionary containing information about one car. Then reference the dictionary in a template.

But what if the owner has several cars? How can I have a template loop over a list of cars?

I am using turbogears2, python 2.7, on debian system.

thanks.


Solution

  • You can find the whole template documentation on Genshi reference (Genshi is the template engine used by TurboGears): http://genshi.edgewall.org/wiki/Documentation/xml-templates.html

    What you are looking for is the py:for attribute which will repeat the tag for each item in a list.