使用 PHPTAL 进行斑马条纹?
我正在尝试 PHPTAL,我想渲染一个带有斑马条纹的表格。 我正在循环访问一个简单的 php assoc 数组 ($_SERVER)。
请注意,我不想使用 jQuery 或类似的东西,我正在尝试学习 PHPTAL 的用法!
目前我的工作方式如下(对于我的喜好来说太冗长了):
<tr tal:repeat="item server">
<td tal:condition="repeat/item/odd" tal:content="repeat/item/key" class="odd">item key</td>
<td tal:condition="repeat/item/even" tal:content="repeat/item/key" class="even">item key</td>
<td tal:condition="repeat/item/odd" tal:content="item" class="odd">item value</td>
<td tal:condition="repeat/item/even" tal:content="item" class="even">item value</td>
</tr>
基本上我想要某种即时的条件赋值,但我不确定语法。
I'm trying out PHPTAL and I want to render a table with zebra stripes. I'm looping through a simple php assoc array ($_SERVER).
Note that I don't want to use jQuery or anything like that, I'm trying to learn PHPTAL usage!
Currently I have it working like this (too verbose for my liking):
<tr tal:repeat="item server">
<td tal:condition="repeat/item/odd" tal:content="repeat/item/key" class="odd">item key</td>
<td tal:condition="repeat/item/even" tal:content="repeat/item/key" class="even">item key</td>
<td tal:condition="repeat/item/odd" tal:content="item" class="odd">item value</td>
<td tal:condition="repeat/item/even" tal:content="item" class="even">item value</td>
</tr>
Basically I want some kind of conditional assignment on the fly, but I'm unsure of the syntax.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过编写
phptal_tales_evenodd()
函数来创建表达式修饰符(请参阅手册中的phptal_tales()
):You could create expression modifier by writing
phptal_tales_evenodd()
function (seephptal_tales()
in manual):好吧,看来我有自己的答案,尽管我仍然认为这相当丑陋:
有人在寻找 PHPTAL 时有更优雅的东西吗?
Well, it seems like I have my own answer, though I still think this is rather ugly:
Anyone got anything more graceful looking for PHPTAL?