如何使用Chameleon或Zope页面模板轻松创建CSS斑马条纹?我想向表的每一行添加odd
和even
类,但是即使使用条件表达式也要使用带有repeat/name/odd
或repeat/name/even
看起来比较冗长的条件:
<table>
<tr tal:repeat="row rows"
tal:attributes="class python:repeat['row'].odd and 'odd' or 'even'">
<td tal:repeat="col row" tal:content="col">column text text</td>
</tr>
</table>
如果您要计算多个类,这将特别繁琐。
该repeat
变量的Zope页面模板实现具有一个文档不足的额外参数,parity
它为您提供字符串'odd'
或'even'
在迭代之间交替:
<table>
<tr tal:repeat="row rows"
tal:attributes="class repeat/row/parity">
<td tal:repeat="col row" tal:content="col">column text text</td>
</tr>
</table>
这也更容易插入到字符串表达式中:
tal:attributes="class string:striped ${row/class} ${repeat/row/parity}"
这也适用于变色龙。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句