使用 PHPTAL 进行斑马条纹?

发布于 2024-07-09 12:51:05 字数 683 浏览 9 评论 0原文

我正在尝试 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疏忽 2024-07-16 12:51:05

您可以通过编写 phptal_tales_evenodd() 函数来创建表达式修饰符(请参阅手册中的 phptal_tales() ):

<td tal:attributes="class evenodd:repeat/item/odd">

You could create expression modifier by writing phptal_tales_evenodd() function (see phptal_tales() in manual):

<td tal:attributes="class evenodd:repeat/item/odd">
两相知 2024-07-16 12:51:05

好吧,看来我有自己的答案,尽管我仍然认为这相当丑陋:

<tr tal:repeat="item server">
  <td tal:content="repeat/item/key" tal:attributes="class php: repeat.item.odd ? 'odd' : 'even'">item key</td>
  <td tal:content="item" tal:attributes="class php: repeat.item.odd ? 'odd' : 'even'">item value</td>
</tr>

有人在寻找 PHPTAL 时有更优雅的东西吗?

Well, it seems like I have my own answer, though I still think this is rather ugly:

<tr tal:repeat="item server">
  <td tal:content="repeat/item/key" tal:attributes="class php: repeat.item.odd ? 'odd' : 'even'">item key</td>
  <td tal:content="item" tal:attributes="class php: repeat.item.odd ? 'odd' : 'even'">item value</td>
</tr>

Anyone got anything more graceful looking for PHPTAL?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文