Smarty:根据数组中的项目数输出行
我正在使用 Smarty 将数组输出到 HTML 表。我希望表的每一行中的项目不超过 8 个。如果数组有超过 8 个项目,则代码将为溢出的项目创建一个新行。
我该怎么做?这清楚吗?
I am using Smarty to output an array to an HTML table. I want each row of the table to have no more than 8 items in it. If the array has more than 8 items then the code would make a new row for the overflowing items.
How can I do this? Is this clear?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经很久没有使用 Smarty 了,但是你应该能够像这样执行此操作:
如果索引可被 8 整除,则模运算符仅返回 0,因此在每第 9 项之前它都会添加一个新行。我们不希望第一项发生这种情况,所以我们也检查一下。
It's been a long time since I've used Smarty, but you should be able to do this like this:
The modulus operator only returns 0 if the index is dividable by 8, So before every 9th item it adds a new row. We don't want this for the first item to happend so let's check that as well.
我过去是这样做的:
Here's how I did it in the past: