[ZPT] repeating a table cell conditionally

Thomas Olsen tol@tanghus.dk
Mon, 27 Aug 2001 22:17:41 +0200


Maybe this will do it (untested):

<tr>
  <span 
    tal:omit-tag="python:1"  
    tal:repeat="year python:range(1989, 2002)">
  <th tal:define="volume python:path('here/%s' % year) or nothing"
      tal:condition="volume"
      tal:content="volume/id">
      Year
  </th>
  </span>
</tr>


On Monday 27 August 2001 22:17, Clint Brubakken wrote:
> I'm pretty new to page templates, and have been reading all I could find
> on it, and bugging philh on #zope on open projects, and I have a
> question on how to do something:
>
> I have a table and a row, and I want to repeat cells  over a sequence
> and if the current item in the sequence it a vaild object print its id
> in a <th></th>, if not do nothing.
> Here is what I had, but it adds an empty <th></th> pair  :
>
> <tr><th tal:repeat="year python:range(1989, 2002)">
> 	<span tal:define="volume python:path('here/%s' % year) or nothing"
>        tal:condition="volume"
> tal:replace="volume/id">Year</span></th></tr>
>
>
> the best solution I found was :
> <tr><th tal:repeat="year python:range(1989, 2001)"
> tal:replace="python:test(exists(path(string('here/$year'))),
> '<th>%s</th>'% path(string('here/$year')).title_or_id(),
> '')">Year</th></tr>
>
>
> which actually doesn't work.
>
> Essentially I need define and condition to have a lower precedence then
> repeat in the tag. The solution in the TAL spceification of surrounding
> it with another tag can't work as no tag can come between <tr> and <th>

-- 
Regards,
	Thomas Olsen

http://www.tanghus.dk