[ZPT] the best way for repeation

Dmitry Matveev Dmitry Matveev <matveev@uralfirm.ru>
Mon, 18 Nov 2002 16:54:18 +0500


Hello!
Depending on the condition I use one of the methods for repeation
(container.sql.discussions.select or container.sql.posts.select).
What way of implimentation is better?:

1. The code
<div tal:condition="request/discussion_id | nothing" tal:omit-tag="">
  <span tal:define="global discussions
python:container.sql.discussions.select(request)"/>
</div>
<div tal:condition="request/post_id | nothing" tal:omit-tag="">
  <span tal:define="global discussions
python:container.sql.posts.select(request)"/>
</div>
<table>
<tal:discussion tal:condition="discussions">
<tr tal:repeat="discussion discussions">
....
</table>

2. The code is much longer here
<div tal:condition="request/discussion_id | nothing" tal:omit-tag="">
<table>
  <tal:discussions  tal:define="discussions
python:container.sql.discussions.select(request)"/>
<tr tal:repeat="discussion discussions">
....
</table>
</div>

<div tal:condition="request/post_id | nothing" tal:omit-tag="">
<table>
  <tal:discussions  tal:define="discussions
python:container.sql.posts.select(request)"/>
<tr tal:repeat="discussion discussions">
....
</table>
</div>

3. The code is similar to the first,  but to use request until global.
<div tal:condition="request/discussion_id | nothing" tal:omit-tag="">
  <span
  tal:replace="request.set('discussions',container.sql.discussions.select(request))"/>
</div>
<div tal:condition="request/post_id | nothing" tal:omit-tag="">
  <span
  tal:replace="request.set('discussions',container.sql.posts.select(request))"/>
</div>
<table>
<tal:discussion tal:condition="discussions">
<tr tal:repeat="discussion discussions">
....
</table>


-- 
Best regards,                          www.uralfirm.ru
Dmitry Matveev                         mailto:matveev@uralfirm.ru