Mar*_*ers 50 css zope zpt chameleon template-tal
如何使用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>
Run Code Online (Sandbox Code Playgroud)
如果您有多个要计算的类,这将变得特别繁琐.
Mar*_*ers 36
Zope的页面模板实现了repeat变量的下记录的额外的参数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>
Run Code Online (Sandbox Code Playgroud)
插入字符串表达式也更容易:
tal:attributes="class string:striped ${row/class} ${repeat/row/parity}"
Run Code Online (Sandbox Code Playgroud)
这也适用于变色龙.